查看原文:Nginx 实现端口转发——星河赵博客
Summary
Nginx在监听某一端口(如80端口)时,通过配置负载均衡池,根据不同的域名,将同一端口的HTTP/HTTPS请求分发到不同的端口。
实例如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
| upstream one_pool{ server 127.0.0.1:5000; } upstream two_pool{ server 127.0.0.1:6000; }
server { listen 80; server_name one.poryoung.cn; return 301 https://$server_name$request_uri; } server { listen 443; server_name one.poryoung.cn; location / { proxy_pass http://one_pool; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection 'upgrade'; proxy_set_header Host $host; proxy_cache_bypass $http_upgrade; } ssl on; ssl_certificate /.../*.poryoung.cn/fullchain.cer; ssl_certificate_key /.../*.poryoung.cn.key; ssl_session_timeout 5m; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_prefer_server_ciphers on; ssl_ciphers 'EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH'; }
server { listen 80; server_name two.poryoung.cn; return 301 https://$server_name$request_uri; } server { listen 443; server_name two.poryoung.cn; location / { proxy_pass http://two_pool; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection 'upgrade'; proxy_set_header Host $host; proxy_cache_bypass $http_upgrade; } ssl on; ssl_certificate /.../*.poryoung.cn/fullchain.cer; ssl_certificate_key /.../*.poryoung.cn.key; ssl_session_timeout 5m; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_prefer_server_ciphers on; ssl_ciphers 'EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH'; }
|
其中的域名和证书部分需要替换。
Let’s Encrypt已经支持泛域名证书申请,网上有许多教程,比较详细的如Let’s Encrypt免费泛域名证书申请教程步骤,使用ACME.sh
申请。
在申请过程中,./acme.sh --issue -d *.xxorg.com -d xxorg.com --dns
和./acme.sh --renew -d *.xxorg.com -d xxorg.com
命令可能会遇到dns manual mode
警告而失败的情况,在其后加上--yes-I-know-dns-manual-mode-enough-go-ahead-please
即可