Nginx Reverse Proxy for Node.js (Config Snippet + Test with curl)

Running a Node.js app behind Nginx is a battle-tested pattern: Nginx handles TLS, static files, gzip, and connection upgrades (for WebSockets), while your Node app focuses on business logic. This guide gives you a clean, production-ready Nginx config and shows how to test it with curl.


What you’ll set up

  • A Node.js app listening on 127.0.0.1:3000
  • Nginx reverse proxy on port 80/443
  • WebSocket support
  • Gzip compression & basic hardening
  • Simple tests with curl

Works on Ubuntu/Debian and CentOS/RHEL. Adjust paths if your distro uses different Nginx locations.


1) Minimal Node.js app (for testing)

Create a tiny server to verify the proxy:

mkdir -p /var/www/node-app && cd /var/www/node-app
cat > server.js <<'EOF'
const http = require('http');

const server = http.createServer((req, res) => {
  // Simple health route
  if (req.url === '/health') {
    res.writeHead(200, { 'Content-Type': 'application/json' });
    return res.end(JSON.stringify({ ok: true, via: 'node', time: new Date().toISOString() }));
  }

  // Echo headers (useful for proxy tests)
  res.writeHead(200, { 'Content-Type': 'application/json' });
  res.end(JSON.stringify({
    url: req.url,
    headers: req.headers,
    message: 'Hello from Node behind Nginx!'
  }));
});

server.listen(3000, '127.0.0.1', () => {
  console.log('Node app listening on http://127.0.0.1:3000');
});
EOF

node server.js

You should see: Node app listening on http://127.0.0.1:3000


2) (Optional) Keep Node running with systemd

sudo tee /etc/systemd/system/node-app.service >/dev/null <<'EOF'
[Unit]
Description=Node.js Example App
After=network.target

[Service]
WorkingDirectory=/var/www/node-app
ExecStart=/usr/bin/node server.js
Restart=always
RestartSec=3
Environment=NODE_ENV=production
User=www-data
Group=www-data

[Install]
WantedBy=multi-user.target
EOF

sudo systemctl daemon-reload
sudo systemctl enable --now node-app
sudo systemctl status node-app --no-pager

On CentOS/RHEL, the Node path is usually /usr/bin/node too; user/group may be nginx instead of www-data.


3) Nginx reverse proxy config (HTTP)

Create a site config (Debian/Ubuntu style):

sudo mkdir -p /etc/nginx/sites-available /etc/nginx/sites-enabled
sudo tee /etc/nginx/sites-available/node-proxy.conf >/dev/null <<'EOF'
# Replace example.com with your domain
server {
    listen 80;
    server_name example.com www.example.com;

    # Gzip for JSON/JS/CSS
    gzip on;
    gzip_types text/plain application/json application/javascript text/css;
    gzip_min_length 1024;

    # Proxy timeouts (tune as needed)
    proxy_connect_timeout 5s;
    proxy_send_timeout 60s;
    proxy_read_timeout 60s;
    send_timeout 60s;

    # Forward real client IPs
    set $upstream http://127.0.0.1:3000;

    location / {
        proxy_pass $upstream;

        # Preserve Host and IP info
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;

        # WebSocket support
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection $connection_upgrade;

        # Don't buffer SSE/WebSockets too aggressively
        proxy_buffering off;
    }

    # Health path can be cached off for clarity
    location = /health {
        proxy_pass $upstream;
        proxy_set_header Host $host;
        proxy_buffering off;
    }

    # Basic hardening
    add_header X-Frame-Options SAMEORIGIN always;
    add_header X-Content-Type-Options nosniff always;

    # Map for Connection upgrade (place in http{} block if in main nginx.conf)
}
EOF

Create a small map to handle Connection header for WS upgrades. Put this once in your global http {} block (e.g., /etc/nginx/nginx.conf), outside the server block:

map $http_upgrade $connection_upgrade {
    default upgrade;
    ''      close;
}

Enable and test:

sudo ln -s /etc/nginx/sites-available/node-proxy.conf /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx

CentOS/RHEL path: often a single /etc/nginx/nginx.conf with server {} blocks in /etc/nginx/conf.d/*.conf. If so, save as /etc/nginx/conf.d/node-proxy.conf and skip the symlink step.


4) Add HTTPS (Let’s Encrypt)

If your DNS points to the server, you can set up TLS quickly:

# Install Certbot
# Ubuntu/Debian:
sudo apt-get update && sudo apt-get install -y certbot python3-certbot-nginx

# CentOS/RHEL (Stream 8/9; may be 'dnf' and package names differ slightly):
# sudo dnf install -y certbot python3-certbot-nginx

# Obtain and auto-configure SSL for the server block with server_name example.com
sudo certbot --nginx -d example.com -d www.example.com

# Auto renewal (usually installed by default)
sudo systemctl status certbot.timer --no-pager

Certbot will add listen 443 ssl http2; and ssl_certificate lines for you.


5) Test with 

curl

A. Test that Nginx reaches Node

# Replace example.com with your domain or server IP (if HTTP only for now)
curl -i http://example.com/health

Expected:

  • HTTP/1.1 200 OK (or HTTP/2 200 if HTTPS)
  • JSON body like: {“ok”:true,”via”:”node”,”time”:”…”}
  • Response header server: nginx (from Nginx) and body says it came from Node

B. Check headers forwarded by Nginx

curl -i http://example.com/ -H "X-Demo: test123"

Look for:

  • Host: example.com
  • x-demo: test123
  • x-forwarded-proto: http (or https if TLS enabled)
  • x-real-ip set to your client IP

C. Test HTTPS (after Certbot)

curl -I https://example.com/health

You should see:

  • HTTP/2 200
  • TLS certificate fields if you add -v

D. (Optional) WebSocket sanity test

If your Node app upgrades connections at /ws, you can verify the handshake:

curl -i -N \
  -H "Connection: Upgrade" \
  -H "Upgrade: websocket" \
  -H "Host: example.com" \
  -H "Origin: https://example.com" \
  http://example.com/ws

You should get 101 Switching Protocols if your backend handles WS.


6) Common pitfalls & fixes

  • 502 Bad Gateway
    • Node app not running or wrong upstream port/host.
    • SELinux (CentOS) may block Nginx from proxying: setsebool -P httpd_can_network_connect 1
  • WebSockets not upgrading
    • Missing proxy_http_version 1.1, Upgrade, and Connection headers.
    • The map $http_upgrade $connection_upgrade must be in http{}.
  • Wrong client IP
    • Ensure proxy_set_header X-Real-IP $remote_addr; and X-Forwarded-For.
  • TLS issues
    • DNS not pointing to server before running Certbot.
    • Port 80/443 blocked by firewall.

7) Full example (drop-in) for 

/etc/nginx/conf.d/node-proxy.conf

# Place this map ONCE in /etc/nginx/nginx.conf inside http { }:
# map $http_upgrade $connection_upgrade { default upgrade; '' close; }

server {
    listen 80;
    server_name example.com www.example.com;

    gzip on;
    gzip_types text/plain application/json application/javascript text/css;
    gzip_min_length 1024;

    set $upstream http://127.0.0.1:3000;

    location / {
        proxy_pass $upstream;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;

        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection $connection_upgrade;

        proxy_buffering off;
        proxy_connect_timeout 5s;
        proxy_send_timeout 60s;
        proxy_read_timeout 60s;
    }

    location = /health {
        proxy_pass $upstream;
        proxy_set_header Host $host;
        proxy_buffering off;
    }

    add_header X-Frame-Options SAMEORIGIN always;
    add_header X-Content-Type-Options nosniff always;
}

Reload Nginx after changes:

sudo nginx -t && sudo systemctl reload nginx

Final checklist

  • Node app runs on 127.0.0.1:3000 (or your chosen port)
  • Nginx config enabled and tested (nginx -t)
  • Health endpoint returns 200 via Nginx
  • TLS installed with Certbot (optional but recommended)
  • curl tests show correct headers and status codes

Tags: Nginx, Node.js, Reverse Proxy, WebSockets, Linux, CentOS, Ubuntu, DevOps

Meta Description: Learn how to put Node.js behind Nginx with a production-ready reverse proxy config, WebSocket support, and quick tests using curl.


Posted

in

by

Comments

91 responses to “Nginx Reverse Proxy for Node.js (Config Snippet + Test with curl)”

  1. Tried a few sites but this one is definitely the most reliable. The payouts are fair and the variety of games is impressive. phlrubyph

  2. Honestly one of the most exciting platforms I have used. Everything is well organized and the rewards are actually worth it. gzoneph

  3. Love the vibe of this site! It is very user friendly and I had a great time winning some credits last night. Cheers! phgzone

  4. Hmm, the RNG focus is key! Analyzing odds requires rigor. For more deep dives, check phdula casino club. Good stuff on the platform’s security too!

  5. My nights just got a whole lot brighter since I discovered this little gem. The interface greets you like an old friend and the game variety keeps every session feeling fresh. I drop by after dinner, claim my daily perk, and enjoy the kind of fair play that actually makes you trust the spin. mxmarte777

  6. I started visiting just to pass the time during lunch breaks and somehow it became my favorite way to unwind after work. The daily free spins keep the momentum going and I never run out of new titles to try. It feels like a friendly neighborhood spot that just gets better with every visit. slotbajionline

  7. I was looking for a straightforward gaming spot without all the complicated rules and this is exactly what I needed. The registration takes seconds and the promotions keep showing up right when I want them. It feels like a personal casino floor tailored just for me. 6777badapp

  8. I have tested dozens of platforms over the years and this one truly stands out for its consistency. Every game loads instantly on my tablet and the sound effects perfectly match the action on screen. I submitted a ticket about my referral bonus and got a detailed reply within fifteen minutes. It is refreshing to see a site that actually cares about player satisfaction. bd3333def

  9. I never leave reviews unless I am really impressed and this platform completely won me over. The welcome bonus was fair and the game library keeps getting better. Customer service replies within minutes and always sounds so ready to help. Will definitely keep playing here. bde2bat

  10. I have tried plenty of mobile gaming sites but this one stands out for its stability. The live chat support is friendly and the game selection covers all my favorites without any lag. Payouts always arrive on time and the bonuses keep getting better. Give this platform a chance today. ssws368

  11. Using GCash for deposits and withdrawals here is just so effortless. It’s the most convenient way to manage my funds while playing. Top tier service. playtimegcashlogin

  12. Downloaded the app and it runs like butter on my phone. The mobile version keeps all the features I need and the bonuses are always fresh. I play during my commute and it makes the ride fly by. 699slotsapk

  13. As a regular player in the Philippines I am always searching for reliable platforms and this one delivers perfectly. The local payment options work flawlessly and support responds in no time. A solid choice for daily play. phpinas777

  14. Just discovered this spot last week and the gameplay flow is seriously smooth. I love how the welcome bonus actually hits the dashboard without any hassle. Customer service replied within minutes when I asked about withdrawal limits. If you are looking for a reliable place to unwind after work, give it a solid try. okbetcasinoonline

  15. Interesting take on balancing entertainment & wellbeing! It’s smart to see platforms like 58jl app download emphasizing responsible gaming-KYC & limits are crucial. Good content overall! 👍

  16. Quick withdrawals and a very fair system. It is hard to find a trustworthy spot these days but pdc88login is legit!

  17. I have tried almost every betting site out there and this one really stands out. The mobile app runs like butter and I never experience lag during live games. Plus the VIP program actually rewards loyal players instead of just promising things. Love it. mmgmm11

  18. Been searching for a reliable sports betting platform for months and finally found a gem. The registration process is super smooth and the bonuses actually come through without any hassle. Highly recommend giving it a shot if you want a seamless experience. Check it out here iw1015register

  19. Switching over to ck444applogin was one of the best moves I made this year. It greets me like an old buddy every time I open the app and the games just flow so naturally. I love how welcoming the whole platform feels. ck444applogin

  20. The payout rates here are actually decent compared to other sites I’ve used. Definitely worth a try. Give idtoge123 a shot if you want a fair experience.

  21. Yo, check out fi777! Heard some good things, might be a decent spot to try your luck. Anyone else had any good experiences? Let me know!

  22. If you’re looking for a quick game to hop on, check out taya999com. Doesn’t take too long or anything to get into it.

  23. Went VIP on 93jlvip, has many perks inside. Feel like checking it out? Access it here: 93jlvip.

  24. I felt really lucky playing here today. The registration process was quick and the games are top-notch. Five stars for lucky53game.

  25. Really impressed with the odds and the overall vibe of the site. It feels very secure and fair for the players. Give br79bet42 a try if you are looking for something fresh.

  26. Finally found a site that actually works without any glitches. Setting up my account was a breeze and I am already seeing great results with ku9iappapk

  27. Finally found a site that doesn’t lag during peak hours. The graphics are crisp and the bonuses are generous. Give kr12kr333 a try, you wont regret it.

  28. The VIP treatment here is legit. I really appreciate how responsive the customer support is whenever I have a question about my bonus. Keep it up! phvipph

  29. Great customer support and even better games. I really appreciate how stable the platform is during peak hours. Keep it up ph7sjili!

  30. Finally found a site that actually works smoothly. The login process is super fast and I didn’t encounter any lags while playing. Highly recommend jiliglorylogin for anyone looking for a reliable platform.

  31. I was looking for a reliable place to register and this was the perfect choice. Everything is streamlined and efficient. Visit aaajili357loginregister

  32. Great interface and the graphics are stunning. It feels like a premium casino experience right from my phone. 38jilicclogin

  33. Signing up was a breeze. I was able to start playing within minutes without any hassle. Go to spintimephsignup to get started.

  34. Downloaded the app yesterday and it runs so smoothly on my phone with no lag during live sessions the daily reward notifications are a nice touch too definitely recommend this to anyone looking for a reliable gaming platform that actually respects your time ad777gamedownload

  35. I really appreciate the transparency of this site. The rewards are clear and the winning feeling is amazing. Best at idhadiah138

  36. Finally found a place that doesn’t glitch out during the big wins. The login process is seamless and the support team is actually helpful. Love d333betlogin.

  37. Finally found a reliable link that actually works without any lag. The login process is super straightforward and secure. Cheers to perabetcasinologin.

  38. Finally a site that doesn’t crash every five minutes. The winning streaks I’ve had here are legendary. Big thanks to phtaya789!

  39. Great platform with a very secure login process. I feel safe depositing my funds here and the customer support is actually helpful. jilibet888login

  40. Logging in is fast and the dashboard is very intuitive. It makes the whole gaming process so much easier. Visit semesta88login now

  41. Super friendly community and a great selection of slots. I always have a blast whenever I log into idcipung138.

  42. I love the daily bonuses they offer. It keeps things exciting even when I am just playing for fun. Big thanks to 56bbet for the great vibes

  43. Really impressed with the customer service and the overall vibe of the site. It is easy to navigate and very rewarding. Visit xojilicasinologin soon.

  44. Lottery patterns are fascinating, but truly random chance reigns supreme! Seeing platforms like juan 365 app casino cater to players with VIP experiences & quick deposits (even crypto!) is interesting. It’s all about responsible fun, right? Hoping for good luck to all!

  45. Honestly the best experience I’ve had in a while. The game variety is insane and the customer support is actually helpful. Big fans of rajabet818com over here!

  46. Anyone had some wins on ff555bet? I’m thinking of giving it a try. The layout looks alright, and I’m always on the lookout for new bonuses!

  47. I’ve been looking for a reliable spot to play and this one really hits the mark. The interface is smooth and the payouts are fair. Definitely check out c186game if you want a stress-free experience.

  48. Best platform I’ve used in the Philippines so far. The games are exciting and it feels very fair. Highly recommend giving phjljl2 a try if you love winning.

  49. The app version is so convenient for playing on the go. No lag and very secure transactions. Try wr777app today!

  50. Seriously, the convenience of localized payment options like GCash & PayMaya is a game-changer! Makes trying new games so easy. Thinking of checking out ph3333 slot – quick sign-up sounds perfect for a little fun! Definitely a step up for online gaming in the Philippines.

  51. Best gaming experience I have had in a long time. The bonuses are actually helpful and not just for show. Definitely try ph69jili if you want real action.

  52. Hmm, về cái giao diện đa dạng này thì ổn đấy. Nhưng nhớ xem kỹ phần trải nghiệm người dùng nhé! Mới nghiên cứu qua 6ff vip download, thấy nó rất thân thiện. Chúc mọi người chơi vui!

  53. Really impressed with the loyalty program here. The perks are awesome and the gaming experience is just buttery smooth. Join the club at 50jilivip.

  54. I really appreciate how easy the login process is here. No complicated steps just straightforward gaming. kkslot777login is definitely my new favorite.

  55. Solid experience overall. The withdrawals are processed much faster than other sites I have used. Go for bdp444.

  56. Really enjoying the variety of games here. Everything feels professional and the customer support is super helpful when I have questions. sx777gamelogin

  57. Solid platform with a lot of exciting options. I really appreciate the transparency in their terms. Give phkavbet a go

  58. The VIP treatment here is legit. I feel like a valued player every time I log in. If you want a premium experience, pera789viplogin is the way to go.

  59. Finally found a platform that doesn’t lag during peak hours. The interface is super clean and easy to navigate even for beginners. Highly recommend idstm88 to everyone.

  60. Curious how decision biases skew perceived luck. Understanding the psychology behind the ‘roll’ is key. For a deeper dive, check Lodi291 app casino. 🤔🎲

  61. Everything from the signup to the first win was seamless. The community here is great and the platform is very stable. Big thanks to pharionph.

  62. If you are looking for a place with good odds and a wide range of games then look no further. wc888game is definitely a winner.

  63. Downloaded the game yesterday and I am already hooked. The installation process was very clear and the game is addictive. Check out c666gamedownload

  64. Perfect for local players! The bonuses are generous and the site loads quickly even on mobile data. Glad I found jilibet019philippines.

  65. Signing up was a breeze and I was able to start playing in under two minutes. The welcome bonus really gave me a great head start! plus777asiasignup

  66. Fast deposits and even faster withdrawals. That is all I care about and this site delivers perfectly. Big thanks to phj8jili.

  67. The jackpot hits are real and the payouts are fast. I love the vibe of this site, it really keeps things exciting. Check out slotgembira88 for some luck.

  68. Found this place through a friend and it did not disappoint. The bonuses are actually fair and easy to claim on bdok999.

  69. The most professional betting site I have come across. Everything is transparent and the payouts are prompt. Trust maxbetonline for your gaming needs.

  70. The download process was super easy and the app runs perfectly on my phone. Thanks to sx777gamedownload for the seamless setup.

  71. Finally found a site that actually works without any glitches. Setting up my account was a breeze and I am already seeing great results with ku9iappapk

  72. Just found this between classes! The seamless mobile access and secure encryption at Barangay 777 game make it perfect for quick breaks. Love the extensive slot library without needing heavy downloads.

  73. Everything from the sign up to the first win was seamless. I love how easy it is to navigate through the different categories. br7kbet777 is definitely a winner.

  74. Had a great run yesterday. The customer support at bdtk886 is very responsive and helped me with my deposit instantly.

  75. I hit a decent streak here last night! The slots are exciting and the graphics are top notch. If you love spinning the reels, ph7spins is the place to be.

  76. If you are looking for a professional casino experience from home this is it. The graphics are top notch and the gameplay is fair. Visit betpkonlinecasino today.

  77. The jackpots here are insane! I love how easy it is to navigate the site on my phone. Big thanks to phjilihot777 for the awesome vibes.

  78. Finally found a platform that actually delivers on its promises. The game variety is impressive and I had a great experience with the support team. Highly recommend krmegawins

  79. Integrating Gcash makes everything so much easier. I can play my favorite games without any payment hassle. arionplaygcashgame is super convenient!

  80. The bonuses here are actually generous compared to other sites. It feels like a real paradise for anyone who loves betting. megabetparadise

  81. I have tried plenty of similar sites but this one stands out for its honesty and speed. Deposits clear in seconds and the game variety keeps things fresh. It is seriously the best decision I have made for my downtime. vnf16887

  82. Solid experience so far. The customer service is responsive and the games load quickly. krwinbox88 really delivers a premium feel.

  83. This site has a great winning streak lately. I feel like my luck has improved since I switched to idarushoki. Keep it up!

  84. The app version is so convenient. I can play anywhere and anytime without any hiccups. Download 22jiliapps for the best mobile gaming.

  85. The customer support is actually helpful which is rare these days. I had a small issue with my deposit and they sorted it in minutes. Give au8802com a go.

  86. Dude, reading this made me think about how sketchy some links can be. Like, checking the actual site security before anything else is key, right? Check out 111bit app ডাউনলোড for more info, but stay smart!

  87. This is exactly what I was looking for. The gameplay is intuitive and the rewards are fair. I’ll be spending a lot more of my free time on pkj555game.

  88. Honestly, the process breakdown is solid, but the fund management angle is what really clicked. It’s more structured than I expected! Check out 55577 বৈধ for more insights.

  89. The app version is just so much more convenient than the browser. Everything is snappy and the bonuses for new users are actually decent. Loving br43betapp so far.

  90. The game selection is top notch and the graphics are crisp. I spent hours playing last night and didn’t have a single crash. Big thanks to phpisogame.

  91. Finally found a place that doesn’t lag during peak hours. The customer support was helpful when I had a question about my deposit. Give vnsv6688k a shot.

Leave a Reply

Your email address will not be published. Required fields are marked *