upstream websocket { | |
server localhost:3000; | |
} | |
server { | |
listen 80; | |
server_name localhost; | |
access_log /var/log/nginx/websocket.access.log main; | |
location /socket.io/ { | |
proxy_pass http://websocket; | |
proxy_http_version 1.1; | |
proxy_set_header Upgrade $http_upgrade; | |
proxy_set_header Connection "upgrade"; | |
} | |
location /socket.io/socket.io.js { | |
proxy_pass http://websocket; | |
} | |
location /sample.html { | |
root /usr/share/nginx/html/; | |
} | |
} |
This comment has been minimized.
This comment has been minimized.
I agree ! |
This comment has been minimized.
This comment has been minimized.
It works. ***** |
This comment has been minimized.
This comment has been minimized.
Why are you using http:// protocol instead of ws:// for the proxy_pass direction URL? |
This comment has been minimized.
This comment has been minimized.
Very useful +1! |
This comment has been minimized.
This comment has been minimized.
+1 Greeeeeaaaaaaaaat!!!!! |
This comment has been minimized.
This comment has been minimized.
@isaackg wondering this too. Did you find out? |
This comment has been minimized.
This comment has been minimized.
@isaackg & @CoreyCole Nginx would complain about invalid URL prefix.
|
This comment has been minimized.
This comment has been minimized.
@isaackg @CoreyCole It's because |
This comment has been minimized.
This comment has been minimized.
not according to wikipedia https://en.wikipedia.org/wiki/WebSocket |
This comment has been minimized.
This comment has been minimized.
Should it be put inside http {} block ? |
This comment has been minimized.
This comment has been minimized.
anybody experiencing timeouts after 1-2 minutes? |
This comment has been minimized.
This comment has been minimized.
Thanks for saving my day |
This comment has been minimized.
This comment has been minimized.
INCREDIBLE thank you a lot |
This comment has been minimized.
This comment has been minimized.
@ms4720 nginx doesn't understand the If nothing else, just think of it as a quirk of nginx's implementation |
This comment has been minimized.
This comment has been minimized.
I wish I had the same luck as everyone else commenting in getting this to work :( I tried setting up an nginx reverse websocket proxy and it kept closing my connection immediately (not after 1 minute, but immediately). I created a StackOverflow post about it, but never got any answers. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
@mlakes-sigsci That's actually where I started with getting it set up :) After that I trolled around the internet and found all sorts of blog posts, forum posts, StackOverflow posts, etc. with tips to get it working, and it never did. I later spun up a simple NodeJS WebSocket server and it worked fine, so it was some quirk of the web server that was preventing a reverse proxy -- not an issue with nginx. Instead of diagnosing the problem and figuring it out, we ended up ignoring the problem and finding another solution to our actual issue (I was using a reverse proxy to add a valid SSL certificate to a server being managed by someone else - we just got them to install a valid SSL cert so the proxy wasn't necessary) |
This comment has been minimized.
Very useful!