Put Socket.IO behind NGINX by proxying the Socket.IO path with HTTP/1.1 and explicitly forwarding the WebSocket Upgrade and Connection headers. A working single-node location for a Node.js server on port 3000 is:
Need a server to try this on? Antihost offers Linux VPS plans with NVMe storage, full root access and a 14-day free trial.
location /socket.io/ {
proxy_pass http://127.0.0.1:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_read_timeout 75s;
}
The timeout shown gives Socket.IO’s default heartbeat room to complete. You may use a different value, but it must exceed your actual pingInterval + pingTimeout. The rest of the setup is choosing the correct location, preserving the request path, matching the client and server path settings, and adapting the configuration for TLS or multiple application nodes.
As an Amazon Associate I earn from qualifying purchases.
What NGINX has to do for Socket.IO
Socket.IO normally starts with HTTP long-polling and can upgrade the session to a WebSocket. NGINX is the public-facing server; the Node.js Socket.IO process remains on a private address such as 127.0.0.1:3000. NGINX must forward ordinary polling requests and also permit the HTTP connection to switch protocols when the upstream returns 101 Switching Protocols.
Upgrade and Connection are hop-by-hop headers. They are not passed through a proxy automatically, so the matching NGINX location must set them explicitly. NGINX has supported this WebSocket tunnel mode since version 1.3.13.
#1 Best Overall
- BLUE LIGHT BLOCKING GLASSES: Our blue light glasses for women boast UV400 protection, blocking harmful blue rays from computer screens. With these bluelight glasses women, you can enjoy gaming, reading, or watching TV with no worries of eye strain.
- EYE RELIEF: Our blue light glasses are engineered to reduce blurry vision or strain caused by prolonged screen time. These womens blue light glasses aid in better sleep by preventing blue light from disrupting your natural sleep cycle, helping you fall asleep faster and enjoy a more restful night's sleep, making them the perfect christmas present.
- COMFORTABLE: Crafted from durable material, our trendy blue light glasses for woman or blue light glasses men ensure long-lasting comfort. The high-transmittance lenses accessories, gamer gifts for men, help keep your eyes relaxed. Perfect stocking stuffers, gifts for gamers men, christmas gifts for men, halloween costumes.
- LIGHTWEIGHT: These clear blue light glasses feature a lightweight frame, meaning they’ll stay comfy for long-term wear. Perfect as blue blockers glasses for women or mens blue light glasses, these non-prescription fake glasses for men can be worn throughout the day. The blue light blocking glasses women feature polycarbonate HD lenses, which are anti-reflective and restore true color.
- WORRY-FREE PURCHASE: If you experience any issues, our support team is ready to assist you quickly. These are the perfect costume glasses for cosplay dressing up.
Prerequisites and assumptions
- NGINX is installed and can reload its configuration.
- A Socket.IO server is listening on the address and port you will put in
proxy_pass; the examples use Node.js on127.0.0.1:3000. - The browser-facing hostname resolves to the NGINX machine.
- The Socket.IO client and server agree on the same path. The default path is
/socket.io/. - You can inspect NGINX’s error log and run
nginx -twith the privileges required by your installation.
If the Node.js process listens on another interface or port, replace the upstream address in every example. Do not expose a loopback address to clients; clients connect to the NGINX hostname, not directly to the Node.js process.
Single-node configuration
Proxy only the Socket.IO endpoint
Use a dedicated location when NGINX also serves a game site, API, or static files. This keeps ordinary web requests under their normal locations while sending Socket.IO polling and upgrade requests to Node.js.
Free tools Windows power users keep installed
One-click scans. No signup required.
server {
listen 80;
server_name example.com;
location /socket.io/ {
proxy_pass http://127.0.0.1:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_read_timeout 75s;
}
}
With no URI suffix after the upstream host, this form forwards the complete request URI. A request such as /socket.io/?EIO=4&transport=polling reaches the application with that path and query string intact.
Proxy the whole application
If the Node.js process serves the entire site, put the same directives in a catch-all location instead:
Rank #2
- WINDEX GAMING WIPES: effortlessly clean all your gaming gear and gaming electronics in one easy step with our new Windex Gaming Wipes
- AMMONIA FREE: our ammonia-free formula is safe to use on all of your favorite gaming equipment like consoles, headsets, controllers, screens, keyboards, and more
- PRE-MOISTENED WIPES: each wipe instantly removes dust, dirt, and stubborn smudges and fingerprints leaving a streak-free shine
- ANTI-STATIC: great for cleaning and wiping down your gaming gear and electronics leaving behind no visible residue
- COMPACT RESEALABLE PACKAGE: store your pack of Windex Gaming Wipes anywhere in your home for whenever a quick and easy wipedown is needed
server {
listen 80;
server_name example.com;
location / {
proxy_pass http://127.0.0.1:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_read_timeout 75s;
}
}
A catch-all proxy also sends unrelated HTTP requests to Node.js, so do not use it when NGINX is intended to serve assets or other virtual paths itself.
What each directive controls
| Directive | Purpose | Why Socket.IO needs it |
|---|---|---|
proxy_pass |
Chooses the upstream server and, depending on its form, whether NGINX rewrites the matched URI. | Polling and WebSocket requests must arrive at the Socket.IO endpoint expected by the application. |
proxy_http_version 1.1 |
Uses HTTP/1.1 between NGINX and the upstream. | The protocol upgrade is negotiated over HTTP/1.1. |
proxy_set_header Upgrade $http_upgrade |
Copies the client’s requested protocol upgrade. | Lets the upstream see the WebSocket handshake request. |
proxy_set_header Connection "upgrade" |
Marks the proxied connection for upgrade. | Completes the hop-by-hop header pair required for the tunnel. |
proxy_set_header Host $host |
Preserves the public host name. | Allows host-based routing, origin checks, and application logging to use the browser-facing host. |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for |
Appends the client address to the forwarding chain. | Preserves the originating address for logs and application policy. |
proxy_read_timeout |
Controls how long NGINX waits for upstream traffic before closing an otherwise idle proxied connection. | Must be longer than the Socket.IO heartbeat interval plus timeout. |
Keep the Socket.IO path unchanged
The default client and server path is /socket.io/. NGINX must route that path to the same endpoint. A subtle source of failures is the URI form of proxy_pass:
proxy_pass http://127.0.0.1:3000;has no URI part, so NGINX forwards the full original request URI.proxy_pass http://127.0.0.1:3000/;includes a URI of/. NGINX replaces the part of the request URI that matched the location before forwarding it.
That replacement is useful when you intentionally mount an application under a different public prefix, but it can silently remove or alter /socket.io/ if added accidentally. Decide whether rewriting is wanted, then test both polling and upgrade requests with the resulting path.
Using a custom Socket.IO path
For a custom path such as /realtime/, configure all three layers consistently:
Rank #3
- Ergonomic & Adjustable Design: Fight "text neck" and improve your posture. Designed for comfort, it offers an adjustable height (7.1in-8.5in) (1.4in adjustable range) and angle (5°-85°) Please note: cell phone stand is only 9 inches tall—the length of a standard pencil
- Without blocking subtitles Perfect for office desk Tiktok Face Time Zoom video—this is the ultimate kitchen desk essential for phones! Perfect viewing experience while reducing neck back strain, A must-have for gamers streamers desk, and anyone who values both style and support!
- Sleek & Stable Design fits Otterbox Case: Say goodbye to bent cables, tangles, and tip-overs! LISEN’s stylish adjustable desk phone holder features a built-in charging hole and smart cable management, keeping your phone secure and your workspace clutter-free cool gadgets for men
- ANTI-SLIP DESIGN free hands: The under 10.00 items easy gadgets back and the bottom of this kitchen essentials for women are fully covered by anti-skid silicone, which LISEN stand up desk decor can provide maximum protection device from any scratches and slides
- Your Perfect Viewing Companion:If your product arrives damaged or breaks within 365 days, reach out to LISEN for a quick and hassle-free solution. Struggling with assembly, like tightening the screw? We’ve got your back! Your experience matters to us. (Product including: phone Holder stand*1, screw*1, hexagon screwdriver*1, specification*1)
- Set the Socket.IO server’s path option to
/realtime/. - Set the browser client’s
pathoption to/realtime/. - Change the NGINX location to
location /realtime/and choose aproxy_passform that preserves or deliberately rewrites that path.
location /realtime/ {
proxy_pass http://127.0.0.1:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_read_timeout 75s;
}
A mismatch can look like a networking problem even when the upstream is healthy: NGINX may return a normal application 404 because the request reached Node.js at a path Socket.IO does not handle.
Set a timeout that matches the heartbeat
NGINX’s default proxy_read_timeout is 60 seconds. Socket.IO documents a default pingInterval + pingTimeout total of 45 seconds. The proxy timeout must be greater than that total; otherwise NGINX can close a healthy connection and the client reports a transport close error.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
The example uses proxy_read_timeout 75s, providing margin above the documented defaults. Treat 75 seconds as an example, not a universal requirement. If your Socket.IO server changes either heartbeat setting, calculate the sum and set the NGINX value higher. Also account for expected pauses in your network and event loop. A very large timeout does not repair a dead upstream; it only delays detection of an idle one.
Serve Socket.IO through HTTPS
Terminate TLS in an NGINX server listening on port 443, and keep the WebSocket directives in the Socket.IO location inside that TLS-enabled server block:
Rank #4
- Easy Installation: Our gaming lights have been designed to enhance your entertainment experience. Simply position the led light bar next to your TV or game console to create a game room environment with ease. They come with USB power and a 60 inch cord for direct mounting and mobility
- Audio Syncing & Extensive Mode: The built-in high-sensitivity music sensor allows you to sync the TV led lights to your favorite music. Lights react and move to the beat of music, film and game audio, creating an incredible immersive sound and light experience – and all without the need for an additional hub. You can choose from 64+ patterns, including strobe, illusion, jump, energy, gradient, running, chasing, fluttering mode etc. Each mode can be applied to different scenes
- 64+ Chasing IC+RGB & W Effect: The independent control design of IC+RGB and white all-in-one multifunctional rgbw led bar lights monitor backlight allows you to easily switch the led lights for desk between IC+RGB and white to enjoy a variety of lighting effects, you can choose white lighting mode with high brightness for better illumination when working, etc. Choose IC+RGB lighting mode when you need to create an entertaining atmosphere for the light show, 16 million colours of Color changing rgb light bar let you dance to the beat and create a dynamic party atmosphere
- Dynamic and Dimmable Lights: 1%-full brightness free brightness adjustment gives you the flexibility to adjust dimmable led light bar for room decorations or a variety of occasions
- USB Powered: USB light bars for room can be powered by powernank, usb charger, TV, Monitor, laptop PC mainframe, making behind TV led lighting bar easy to install in any location.TV led lights are powered by the TV usb interface / PC mainframe, can be turned on/off synchronously with TV / PC
server {
listen 443 ssl;
server_name example.com;
ssl_certificate /etc/ssl/example/fullchain.pem;
ssl_certificate_key /etc/ssl/example/privkey.pem;
location /socket.io/ {
proxy_pass http://127.0.0.1:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_read_timeout 75s;
}
}
The browser should use the HTTPS origin. Socket.IO will negotiate the secure WebSocket form when the transport upgrades. Keep certificate and private-key settings in the TLS server block; the upstream connection from NGINX to Node.js can remain HTTP when it is on a trusted private network. If your internal network also requires encryption, use an HTTPS upstream and adjust proxy_pass accordingly, while retaining the HTTP/1.1 and upgrade headers.
Run more than one Socket.IO node
Multiple Node.js processes require an NGINX upstream group:
Do these 3 things before closing this tab:
1Fix the driver behind crashes, sound loss and screen glitches2Repair Windows errors before they cause bigger problems3Scan for outdated or missing drivers - takes under a minuteupstream socketio_nodes {
server 127.0.0.1:3000;
server 127.0.0.1:3001;
}
server {
listen 80;
server_name example.com;
location /socket.io/ {
proxy_pass http://socketio_nodes;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_read_timeout 75s;
}
}
Polling clients make successive HTTP requests. Those requests may need to reach the same Socket.IO node that owns the session, so configure session affinity when your deployment does not share session state through another mechanism. NGINX documents address-based affinity with either ip_hash or hash $remote_addr consistent.
upstream socketio_nodes {
hash $remote_addr consistent;
server 127.0.0.1:3000;
server 127.0.0.1:3001;
}
WebSocket transport keeps one TCP connection for the session, but polling does not have that property. Temporarily forcing clients to use WebSocket can help isolate an affinity problem, but it is a diagnostic step rather than a substitute for designing the multi-node session behavior. Sticky-cookie support is identified in NGINX documentation as requiring a commercial subscription; evaluate that option only if cookie-based affinity is a requirement.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Apply and verify the configuration
- Save the server block in the configuration location used by your NGINX installation.
- Check syntax and referenced files with
nginx -t. Do not reload a configuration that fails this check. - Reload NGINX using your service manager after the test succeeds.
- Open the application through the public HTTP or HTTPS origin, not the Node.js port.
- In browser developer tools, inspect the Network panel for requests under
/socket.io/. Confirm that polling requests reach the expected path and that the WebSocket handshake receives a successful protocol switch. - Watch the NGINX error log and the Node.js log during the connection attempt. The first error after a reload is often more useful than a later client reconnect message.
For a custom path, substitute that path in the browser check. For a multi-node setup, record which upstream handles successive polling requests so you can verify that your affinity rule behaves as intended.
Best Value
- Compatible with Wide Screens - To ensure compatibility with the dual monitor mount, your each monitor must meet three conditions at the same time: First, computer screens size range: 13 to 32 inches. Second, screen weight range: 4.4 to 19.8 lbs. Third, the back of the monitor screen must have VESA mounting holes with a pitch of 75x75mm or 100x100mm.
- Regarding the compatibility with desks - Your desk must meet three conditions at the same time: First, desk material: Only wooden desks are recommended, plastic or glass desks cannot be used. Second, desk thickness range: 0.59" - 3.54". Third, the bottom of the desk should not have any cross beams or panels, as this will interfere with installation. We recommend carefully checking that your desk and monitors meets all above conditions before purchasing.
- Dual C-Clamp Hold - Worried your dual monitors might wobble or slip? Our upgraded base uses a larger platform plus a dual C-clamp structure to lock the dual monitor arm firmly to your desk. Each arm safely keeps your screens steady while you type, click and game—no shaking, no sliding, just a clean and secure setup you can trust every day. It also provides Grommet Mounting installation choice, both options ensure stable and secure fixation for your 0.59" - 3.54" desk.
- Full-Motion Adjustment For Comfortable View - Pull the screen closer when you’re deep in a spreadsheet, push it back to watch videos, or rotate to portrait for coding — moving everything smoothly with just one hand. The monitor stand offers +85°/-50° tilt, ±90° swivel and 360° rotation. Raise your monitor up to 15.75″ to support a healthy sitting posture. Whether you’re working from home, gaming through the night, or switching between video calls and documents, getting the screens to your natural line of sight helps relieve neck, shoulder and back strain so you can stay focused longer with less fatigue.
- Keep Your Desk Organized: By lifting both screens off the desktop, this dual monitor stand opens up valuable space for your keyboard, notebook, docking station or a simple, clutter-free work area. Built-in cable management guides wires along the arms, keeping cords out of sight and out of the way. Enjoy a tidy, modern workstation that looks as good as it feels to use.
Troubleshoot disconnects and failed upgrades
The client reports a transport error or never upgrades
- Check that the request matched the intended NGINX location rather than a more specific location or a static-file handler.
- Confirm
proxy_http_version 1.1,Upgrade, andConnection "upgrade"are all present in that matching block. - Verify the client and server
pathvalues, including the trailing slash convention. - Inspect
proxy_passfor an unintended URI suffix that rewrites the request.
Connections close after roughly a minute
Compare the observed delay with the configured proxy_read_timeout. Then calculate the Socket.IO server’s actual pingInterval + pingTimeout and ensure the NGINX value is higher. A 60-second default can be too close to the documented 45-second default heartbeat once scheduling or network delay is included.
NGINX returns 502 or cannot reach Node.js
- Confirm the Node.js service is running and listening on the exact address and port in
proxy_pass. - From the NGINX host, test reachability of that address and inspect local firewall rules.
- Check the upstream process log for crashes, startup failures, or a listener bound only to a different interface.
- Run
nginx -tagain after correcting the upstream definition, then reload.
Polling works but sessions fail with multiple nodes
Check whether consecutive polling requests are reaching different workers. Add ip_hash or hash $remote_addr consistent, or provide an application-level shared session strategy. If forcing WebSocket transport makes the issue disappear, the difference points to polling affinity rather than the upgrade headers.
HTTPS works for pages but Socket.IO is blocked
- Make sure the Socket.IO location is inside the
listen 443 sslserver block selected for the hostname. - Keep the HTTP/1.1 and upgrade directives in that TLS location; TLS termination does not remove the need to proxy the WebSocket handshake correctly.
- Use the HTTPS origin in the client configuration and check the browser console for mixed-content or certificate errors before debugging NGINX routing.
Production checklist
- Use a dedicated
/socket.io/location unless the whole application belongs behind Node.js. - Preserve the request URI unless an intentional prefix rewrite is part of the design.
- Forward
HostandX-Forwarded-Forso the application receives the public host and client address context. - Set
proxy_read_timeoutabove the configured heartbeat sum, with operational margin. - Use the same custom path in the client, server, and NGINX location.
- For multiple nodes, decide how polling sessions remain on the correct worker before going live.
- Validate with
nginx -t, reload safely, and monitor both proxy and application logs during a real polling-to-WebSocket connection.
Why the common minimal configuration fails
Removing the upgrade headers leaves NGINX treating the request as an ordinary HTTP proxy request, so the WebSocket handshake cannot become a tunnel. Using HTTP/1.0 between NGINX and the upstream prevents the intended upgrade behavior. Adding a slash to proxy_pass without understanding URI replacement can move requests away from /socket.io/. Leaving the 60-second read timeout unchanged can terminate an otherwise healthy session when the heartbeat configuration leaves too little margin. Finally, a load-balanced polling client can lose its session when successive requests land on different workers.
Once those five concerns are handled—upgrade headers, HTTP/1.1, path preservation, heartbeat-aware timeout, and affinity for polling—the reverse proxy is structurally ready for Socket.IO.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.
The Tool Desk
Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →




