"Cannot GET" on reverse proxy from Nginx to socket.io on express.js "Cannot GET" on reverse proxy from Nginx to socket.io on express.js express express

"Cannot GET" on reverse proxy from Nginx to socket.io on express.js


This is because SocketIO uses /socket.io path by default, so you need to configure Nginx so that it will proxy not only /node request, but /socket.io too:

location ~ ^/(node|socket\.io) {    #your proxy directives}

(By the way, it looks like you have typos: you wrote proxypass, but the correct form is proxy_pass. The same goes to other proxy directives)

You also need to perform one more edit in your NodeJS server file. Replace:

app.get('/', function(req, res){

with:

app.get('/node', function(req, res){

Now it should work.

This is not the only solution. You could also change SocketIO path with some changes in Nginx config, but the solution described above seems the simlest to me. Good luck!


Good aswer by Curious. I want to add that you don't have to adjust the node.js application if you use sub_filter. Your nginx must have been compiled with that module.

location ~ ^/(node|socket\.io) {    #your proxy directives    sub_filter /node /;}


I think it will better if that:

location /node{proxy_pass http://myprivateappserver:3000/; # add "/"proxy_http_version 1.1;proxy_set_header Upgrade $http_upgrade;proxy_set_header Connection 'upgrade';proxy_set_header Host $host;proxy_cache_bypass $http_upgrade;}

the proxy_pass add '/', then app.get('/') is alse ok!