nginx环境下,socket.io连接https

5 篇文章 0 订阅
1 篇文章 0 订阅

nginx环境下,socket.io连接https

项目中有个聊天功能,之前一直请求的 http://ip:端口 的格式,但是升级https之后,就报错了(https请求http服务器路径报错),,,于是找了很多资料配置服务器

1、我使用的是宝塔面板,因此conf 文件pannel文件夹 下面

/www/server/panel/vhost/nginx

找到对应域名下的 conf文件, 在server模块下加入一个location配置:
在这里插入图片描述

location ^~/socket.io {
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_pass http://ip:端口;
    }

注意:找的资料里面,有的写得如下:(不适用当前情况,socket.io路径不对,服务器会报错 404找不到socket.io模块)
location /socket.io/ {
proxy_pass http://ip:端口;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection “Upgrade”;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
}

web端配置的链接socket路径就变成了: https://xx.xx.com , 连接成功

注意事项:server中添加location的时候,一定要引入对应https的加密文件,否则https不起效果(宝塔面板在配置https的时候会自动引入,这里只是说明一种https不起效果的情况)

 ssl_certificate    /www/server/panel/vhost/cert/xx.xxx.com/fullchain.pem;
    ssl_certificate_key    /www/server/panel/vhost/cert/xx.xxx.com/privkey.pem;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
    ssl_ciphers ECxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxHE;
    ssl_prefer_server_ciphers on;
    ssl_session_cache shared:SSL:10m;
    ssl_session_timeout 10m;
    error_page 497  https://$host$request_uri;

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值