简体   繁体   中英

Nginx proxy special uri to socket.io

I want to use nginx to proxy url like https://api.example.com/wss/... to many nodejs servers(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";
        }

After this , I want to attach my service like "wss://api.example.com/wss/" But when this request to nodejs servers , It will not request http://127.0.0.1:8080/ but http://127.0.0.1:8080/wss/ , and socket.io will not work in this URI . How to solve this problem ?

As @Richard Smith said in comments , it did works!

Thanks!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM