极客大本营 2018-09-17 11:29 采纳率: 100%
浏览 6841
已采纳

Nginx如何实现一个域名多个端口共用一个证书?

# 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的ssl证书,8080是我的项目,8081是tomcat图片服务器,现在8080已经有ssl证书了,但是8081没有,运这样配置nginx运行不起来,求解~有什么办法~

  • 写回答

4条回答

  • a331895809 2018-09-18 04:35
    关注

    你的SSL的证书是泛域的(xxx.com),还是www.xxx.com的? 如果是www.xxx.com的SSL证书就不可以,是泛域的就没问题

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?