本文共 1079 字,大约阅读时间需要 3 分钟。
Nginx经常被用于终结SSL连接,可能是因为上游服务器不能够使用SSL。要使用SSL就需要在编译安装时在Nginx的二进制文件中添加--with_http_ssl_module模块,并且要安装ssl证书和秘钥。
以下示例代码表示对客户端和反向代理之间的流量进行加密,主要应该在内部网络建设安全性很高的情况下。
server { listen 443 default ssl; server_name www.test.com; ssl_prefer_server_ciphers on; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_certificate conf.d/cert/server.crt; ssl_certificate_key conf.d/cert/server.key; ssl_session_timeout 5m; ssl_session_cache shared:WEB:10m; ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE; location / { proxy_http_version 1.1; proxy_set_header X-FORWARDED-PROTO https; #使上游服务器的应用程序知道原始请求使用了https proxy_set_header Host $host; proxy_pass http://upstream; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; }}# http重定向到httpsserver { listen 80; server_name www.test.com; rewrite ^(.*)$ https://$host$1 permanent;}
转载于:https://blog.51cto.com/10316297/2372011