知道的越多,不知道的越多,NGINX的功能远比我所能理解的多太多了。
山高万仞,只登一步。披荆斩棘,行则将至。
NGINX端口重定向(80 to 443)
在生产环境中,一般不会使用http协议进行Web访问,都是使用https加密的方式进行Web访问,http和https各自监听的端口都不一样,那多余的80端口,该何去何从?一个比较合适的做法是端口重定向,使用NGINX的重写功能,将访问80端口的请求自动转发给443端口,下面是一个例子:
折叠代码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
| server { listen 443 ssl; server_name itellyou.cf; ssl_certificate /opt/ssl/itellyou.cf.pem; ssl_certificate_key /opt/ssl/itellyou.cf.key; ssl_session_cache shared:SSL:1m; ssl_session_timeout 5m; ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4; ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3; ssl_prefer_server_ciphers on;
location / { root /usr/share/nginx/html; index index.php index.html index.htm; } }
server { listen 80; server_name itellyou.cf; rewrite ^(.*)$ https://$host$1; location / { index index.php index.html index.htm; } }
|
NGINX反向代理
反向代理不加密站点
折叠代码1 2 3 4 5 6 7 8 9 10 11
| server { listen 80; server_name ai.itellyou.cf;
location / { proxy_pass http://itellyou.cf:30080; } }
|
反向代理SSL加密站点
折叠代码1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| server { listen 443 ssl; server_name ai.itellyou.cf; ssl_certificate /opt/ssl/ai.itellyou.cf.pem; ssl_certificate_key /opt/ssl/ai.itellyou.cf.key; ssl_session_cache shared:SSL:1m; ssl_session_timeout 5m; ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4; ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3; ssl_prefer_server_ciphers on;
location / { proxy_pass http://itellyou.cf:30080; } }
|