# http自动转https
server {
listen 80;
index index.php index.htm index.html;
server_name xxx.com www.xxx.com; #监听nginx所在服务器8080端口
return 301 https://www.xxx.com$request_uri;
}
#ssl证书配置
server {
listen 443;
server_name www.xxx.com;
ssl on;
ssl_certificate 1_xxx.com_bundle.crt;
ssl_certificate_key 2_xxx.com.key;
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; #按照这个协议配置
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE; #按照这个套件配置
ssl_prefer_server_ciphers on;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
#你的项目端口号
proxy_pass http://127.0.0.1:8080/;
proxy_redirect off;
}
}
server {
listen 443;
server_name www.xxx.com:8081;
ssl on;
ssl_certificate 1_xxx.com_bundle.crt;
ssl_certificate_key 2_xxx.com.key;
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; #按照这个协议配置
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE; #按照这个套件配置
ssl_prefer_server_ciphers on;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
#你的项目端口号
proxy_pass http://127.0.0.1:8081/;
proxy_redirect off;
}
}

Nginx如何实现一个域名多个端口共用一个证书?
- 写回答
- 好问题 0 提建议
- 关注问题
- 邀请回答
-
4条回答 默认 最新
- a331895809 2018-09-18 04:35关注
你的SSL的证书是泛域的(xxx.com),还是www.xxx.com的? 如果是www.xxx.com的SSL证书就不可以,是泛域的就没问题
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报