Nginx常常被用于终结SSL链接,多是由于上游服务器不可以使用SSL。要使用SSL就须要在编译安装时在Nginx的二进制文件中添加--with_http_ssl_module模块,而且要安装ssl证书和秘钥。html
如下示例代码表示对客户端和反向代理之间的流量进行加密,主要应该在内部网络建设安全性很高的状况下。安全
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重定向到https server { listen 80; server_name www.test.com; rewrite ^(.*)$ https://$host$1 permanent; }