【发布时间】:2017-01-14 09:04:59
【问题描述】:
我想使用 nginx 将 https://api.example.com/wss/... 之类的 url 代理到许多 nodejs 服务器(socket.io):
upstream websocket {
ip_hash;
server 127.0.0.1:8080;
server 127.0.0.1:8081;
server 127.0.0.1:8082;
}
location /wss/
{
proxy_pass http://websocket;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
在此之后,我想附加我的服务,如"wss://api.example.com/wss/"
但是当这个请求到nodejs服务器时,它不会请求http://127.0.0.1:8080/而是http://127.0.0.1:8080/wss/,并且socket.io不会在这个URI中工作。
如何解决这个问题?
【问题讨论】:
-
尝试:
proxy_pass http://websocket/;(尾随/)。详情请见this document。
标签: node.js nginx websocket proxy socket.io