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

2019-09-27 15:25:51 +08:00
 YFeei

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

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

1483 次点击
所在节点    问与答
3 条回复
mikeguan
2019-09-27 19:05:16 +08:00
proxy pass 后面不需要路径了
itmyhome126
2019-09-27 20:14:09 +08:00
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
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;

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

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

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

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

© 2021 V2EX