Answer the question
In order to leave comments, you need to log in
Why doesn't socket.io work through a proxy?
There is an application in /web/myapp/. The client is connected to:
let socket = io.connect('http://domain.com/web/myapp/ ', {path: '/myapp'});
upstream myapp_socket {
ip_hash;
server 127.0.0.1:8080;
}
location /web/myapp/ {
proxy_pass http://myapp_socket/;
proxy_read_timeout 1000s;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_redirect off;
proxy_pass_request_headers on;
proxy_cache off;
proxy_buffering off;
}
location ~ ^/(socket\.io) {
proxy_pass http://myapp_socket;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
Answer the question
In order to leave comments, you need to log in
because socket.io is "listening to path" /socket.io and not just "directly"
https://github.com/socketio/socket.io/blob/master/...
Then in order to run the second application, will I have to duplicate this rule under the new upstream?
How is it done correctly?
upstream myapp_2_socket {
ip_hash;
server 127.0.0.1:2255;
}
location /web/myapp2/ {
proxy_pass http://myapp_2_socket/;
...
}
location ~ ^/(socket\.io) {
proxy_pass http://myapp_2_socket;
...
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question