V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
YFeei
V2EX  ›  问与答

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

  •  
  •   YFeei · Sep 27, 2019 · 2233 views
    This topic created in 2416 days ago, the information mentioned may be changed or developed.

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

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

    3 replies    2019-09-27 21:15:40 +08:00
    mikeguan
        1
    mikeguan  
       Sep 27, 2019 via Android
    proxy pass 后面不需要路径了
    itmyhome126
        2
    itmyhome126  
       Sep 27, 2019   ❤️ 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
       Sep 27, 2019
    @itmyhome126 可以用,感谢!
    学的不深,还没搞清楚原理
    区别点:
    proxy_set_header X-Forwarded-Proto https;
    proxy_next_upstream off;
    proxy_redirect off;
    proxy_set_header Host $http_host;
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2747 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 15:37 · PVG 23:37 · LAX 08:37 · JFK 11:37
    ♥ Do have faith in what you're doing.