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

小白,请教一个 nginx websocket 的配置问题

  •  
  •   YFeei · 2019-09-27 15:25:51 +08:00 · 1475 次点击
    这是一个创建于 1666 天前的主题,其中的信息可能已经有所发展或是发生改变。

    直接使用 ws://ip:8080/chat 可以访问,正常使用。 但是配置域名进行转发会报 404,似乎 nginx 就没转发到方法里 http://ww1.sinaimg.cn/large/006T7FKhly1g7e3mutt3kj311802774m.jpg

    以下是 nginx 配置 http://ww1.sinaimg.cn/large/006T7FKhly1g7e3qbvsrtj30lv0fodgp.jpg

    3 条回复    2019-09-27 21:15:40 +08:00
    mikeguan
        1
    mikeguan  
       2019-09-27 19:05:16 +08:00 via Android
    proxy pass 后面不需要路径了
    itmyhome126
        2
    itmyhome126  
       2019-09-27 20:14:09 +08:00   ❤️ 1
    location /xxxxx{
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_set_header X-Forwarded-Proto https;
    proxy_next_upstream off;
    proxy_redirect off;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_pass http://ip:port;
    }

    希望对你有帮助
    YFeei
        3
    YFeei  
    OP
       2019-09-27 21:15:40 +08:00
    @itmyhome126 可以用,感谢!
    学的不深,还没搞清楚原理
    区别点:
    proxy_set_header X-Forwarded-Proto https;
    proxy_next_upstream off;
    proxy_redirect off;
    proxy_set_header Host $http_host;
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1649 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 16:45 · PVG 00:45 · LAX 09:45 · JFK 12:45
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.