Nginx配置https
- 安装Nginx
- 修改nginx.conf配置文件
1 upstream tomcat { 2 server 127.0.0.1:8083 fail_timeout=0; #后端服务地址 3 } 4 server { 5 listen 443; 6 ssl on; 7 server_name gdufe888.com; #申请证书的域名 8 // 证书 9 ssl_certificate b.pem; 10 ssl_certificate_key a.key; 11 ssl_session_timeout 5m; 12 // 加密算法 13 ssl_protocols TLSv1 TLSv1.1 TLSv1.2 SSLv2 SSLv3; 14 ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP; 15 ssl_prefer_server_ciphers on; 16 17 location / { 18 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 19 proxy_set_header Host $http_host; 20 proxy_set_header X-Forwarded-Proto https; 21 proxy_redirect off; 22 proxy_connect_timeout 240; 23 proxy_send_timeout 240; 24 proxy_read_timeout 240; 25 proxy_pass http://tomcat; 26 } 27 } 28 server { 29 listen 80; 30 server_name gdufe888.com; #http访问入口 31 location / { 32 rewrite ^ https://$http_host$request_uri? permanent; #强制跳转到HTTPS上 33 } 34 }
结果如下: