CodexBloom - Programming Q&A Platform

Unexpected Nginx 502 Bad Gateway scenarios After Upgrading to Ubuntu 22.10

πŸ‘€ Views: 54 πŸ’¬ Answers: 1 πŸ“… Created: 2025-08-06
nginx ubuntu node.js 502-bad-gateway web-server JavaScript

I'm refactoring my project and After trying multiple solutions online, I still can't figure this out... I'm working with a frustrating scenario after upgrading my server from Ubuntu 22.04 LTS to 22.10 where my Nginx setup is throwing a 502 Bad Gateway behavior when trying to connect to my backend application running on Node.js. I confirmed that Nginx is running properly and its configuration seems correct. Here’s the relevant server block from my Nginx configuration: ```nginx server { listen 80; server_name example.com; location / { proxy_pass http://localhost:3000; 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; } } ``` Additionally, Node.js is also running on the same server and I can access it directly via `curl http://localhost:3000`, which returns the expected JSON response. However, when I try to access my application through Nginx, I receive the following behavior in the Nginx behavior log: ``` 2023/10/15 10:25:43 [behavior] 12345#12345: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 192.168.1.10, server: example.com, request: "GET / HTTP/1.1", upstream: "http://localhost:3000/", host: "example.com" ``` I checked my firewall settings and ensured that UFW is allowing traffic on port 80. I also tried restarting both Nginx and my Node.js application, but the scenario continues. Any suggestions on what might be causing this 502 behavior or how to troubleshoot further would be greatly appreciated. I'm working on a API that needs to handle this. What's the best practice here? What am I doing wrong? I'd be grateful for any help.