Facebook Pixel

How do I configure Nginx for Socket.io WebSocket support?

Add a location /socket.io/ block with proxy_pass, proxy_http_version 1.1, and the Upgrade and Connection headers set to 'upgrade'. These headers are critical without them, WebSocket connections will fail.

Verify This Answer

Cross-check this information using these trusted sources:

More FAQs in Configuring Nginx as a Reverse Proxy on EC2 Routing Traffic to Node.js

Nginx handles port management (80/443 while Node.js uses 3000), SSL termination, static file serving, load balancing, WebSocket proxying for Socket.io, and gzip compression. Node.js doesn't need to run as root or handle SSL directly.

They pass the client's real IP address to the Node.js app. Without them, Node.js sees Nginx's IP (127.0.0.1) instead of the actual client IP, which breaks IP-based features like rate limiting and logging.

Create a file in /etc/nginx/sites-available/, create a symbolic link to /etc/nginx/sites-enabled/, remove the default site, test with sudo nginx -t, and restart with sudo systemctl restart nginx.

Still have questions?

Browse all our FAQs or reach out to our support team

Want to upskill yourself?

Our courses are taking a Coffee break, but your curiosity shouldn't. Stay engaged with namastedev linkedin, youtube, discord and other resources while you wait.

0
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.