V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
remember5
V2EX  ›  问与答

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

  •  
  •   remember5 · 2022-01-07 18:11:42 +08:00 · 1011 次点击
    这是一个创建于 811 天前的主题,其中的信息可能已经有所发展或是发生改变。

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

    目前还没有啥进展,如有进展会同步出来,希望有懂的大佬指点下,感激不尽
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1385 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 17:37 · PVG 01:37 · LAX 10:37 · JFK 13:37
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.