Answer the question
In order to leave comments, you need to log in
How to run socket.io over WS[WSS] proxied to another server?
There is a server mysite.com Launched nginx version == 1.16.0. The link mysite.com/app is proxied to mysite-srv.com:30001. Mysite-srv.com is running nodejs and socket.io app on port == 30001. Client connects to mysite.com/app - everything works. nginx config:
server {
...
location /app/ {
proxy_pass http://mysite-srv.com/app:30001;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
}
location /socket.io/ {
proxy_pass http://mysite-srv.com/app:30001;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
}
...
}
server {
...
location /app/ {
location /app/1/ {
proxy_pass http://mysite-srv.com/app:30001;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
}
location /app/2/ {
proxy_pass http://mysite-srv.com/app:30002;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
}
}
location /socket.io/ {
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header Host $host;
#Здесь я направляю куда мне надо
if ($http_referer ~* /app/1/.*) {
proxy_pass http://mysite-srv.com/app:30001;
}
if ($http_referer ~* /app/2/.*) {
proxy_pass http://mysite-srv.com/app:30002;
}
}
...
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question