宝塔/Nginx/WebSocket

记录下,宝塔配置默认wss无法连接

选择网站 ->设置->反向代理->没有就添加一个,有就直接点配置文件

#PROXY-START/

location /
{
    proxy_pass http://localhost:端口/;
    proxy_set_header Host www.xxx.com;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header REMOTE-HOST $remote_addr;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection $connection_upgrade;
    proxy_http_version 1.1;
    # proxy_hide_header Upgrade;

    add_header X-Cache $upstream_cache_status;

    #Set Nginx Cache
    
    set $static_filesSQnNhw0 0;
    if ( $uri ~* "\.(gif|png|jpg|css|js|woff|woff2)$" )
    {
    	set $static_filesSQnNhw0 1;
    	expires 1m;
        }
    if ( $static_filesSQnNhw0 = 0 )
    {
    add_header Cache-Control no-cache;
    }
}

#PROXY-END/

加两行

proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";

改动后就是这样

#PROXY-START/

location /
{
    proxy_pass http://localhost:端口/;
    proxy_set_header Host www.xxx.com;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header REMOTE-HOST $remote_addr;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection $connection_upgrade;
    proxy_http_version 1.1;
    # proxy_hide_header Upgrade;

    add_header X-Cache $upstream_cache_status;

    #Set Nginx Cache
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    
    set $static_filesSQnNhw0 0;
    if ( $uri ~* "\.(gif|png|jpg|css|js|woff|woff2)$" )
    {
    	set $static_filesSQnNhw0 1;
    	expires 1m;
        }
    if ( $static_filesSQnNhw0 = 0 )
    {
    add_header Cache-Control no-cache;
    }
}

#PROXY-END/

反向代理这么加

最后提一嘴

解决nginx下websocket的长连接问题icon-default.png?t=N7T8https://baijiahao.baidu.com/s?id=1714370851394804830&wfr=spider&for=pc这个文章有用,好东西

分享一个十分精简的开发框架,十分钟上手

dev-tmpl: 快速开发框架

挺好用的,简单,灵活

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值