不懂就问,Nginx 使用 80 端口无法代理 Netty 的 websocket

2022-01-07 18:11:42 +08:00
 remember5

最近在看 netty 相关的知识,尝试了在 springboot 中使用 netty ,看的这个博主的文章,https://juejin.cn/post/6844904110576107534 (按照文章搭建的项目) 项目在本地正常启动,网页测试访问本地 ip+port 访问 websocket 正常访问

发现在部署到服务器的时候,无法用域名直接访问 netty 中的 websocket ,而用域名+port(非 80)的方式可以访问

netty 使用的端口是58080,nginx 中的 proxy 也正常,尝试了网上的一些方案,添加了proxy_set_header等,还是无法解决这个问题,麻烦懂得大佬指导一下,感谢🙏

nginx 的配置如下

worker_processes  1;

events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    sendfile        on;
    keepalive_timeout  65;

   map $http_upgrade $connection_upgrade {
      default upgrade;
      '' close;
   }

    server {
        listen       80;
        server_name  xx.xx.com;
        default_type  application/octet-stream;
        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        
        location /ws {
            proxy_pass http://127.0.0.1:58080;  
            proxy_read_timeout 120s;
            proxy_redirect off;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection $connection_upgrade;
            proxy_set_header Host $host;
            proxy_set_header X-Forwarded-Proto $scheme;
            proxy_set_header X-Forwarded-Port $server_port;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

     
    }

}

1032 次点击
所在节点    问与答
4 条回复
lindas
2022-01-07 18:58:11 +08:00
有没有可能是服务器商把你的请求拦截了
vvhhaaattt
2022-01-08 09:12:34 +08:00
把日志打开看日志啊……排查问题把日志关掉是什么操作
remember5
2022-01-10 16:44:40 +08:00
@vvhhaaattt #2 nginx 默认有配置日志,连接并无响应,日志显示 notice signal process started
remember5
2022-01-10 17:22:41 +08:00
更新一下:
1. 使用 ip+port(任何端口)都是可以访问 websocket 的
2. 使用域名+(非 80 )也是可以访问的
3. 已经问过云服务商,并不会做任何拦截和处理
4. 域名是(阿里云),服务器是(腾讯云)

目前还没有啥进展,如有进展会同步出来,希望有懂的大佬指点下,感激不尽

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/826886

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX