By Ruz
I recently upgraded my DigitalOcean droplet from Ubuntu 22.04 to Ubuntu 24.04 LTS. After the upgrade, nginx started returning 502 Bad Gateway errors for all my sites.
I have checked the following so far:
Here is the relevant error from /var/log/nginx/error.log:
connect() failed (111: Connection refused) while connecting to upstream
My nginx config uses proxy_pass to forward requests to a Node.js application running on port 3000. The app works fine when accessed directly but nginx cannot proxy to it.
I suspect something changed with systemd socket activation or AppArmor profiles in Ubuntu 24.04 Noble Numbat. Has anyone else experienced this issue after upgrading?
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
Heya,
the connect() failed (111: Connection refused) while connecting to upstream error almost always means an issue with the app behind the reverse proxy. Check the error logs of the app. It can be a broken function or something.
Hi there,
The error is clear: connection refused on port 3000 means Nginx is reaching the right place but nothing is listening there. Since the app works when you curl it directly, the issue is likely that the app is binding to 127.0.0.1:3000 on one network interface but Nginx is trying to connect to a different one, or the app is not actually running under the same context after the upgrade.
A few things to check:
Confirm the app is actually listening and on which interface:
ss -tlnp | grep 3000
If it shows 127.0.0.1:3000 you are fine. If it shows ::1:3000 (IPv6 only) and your Nginx config uses proxy_pass http://localhost:3000, that could be the issue since localhost resolves differently on Ubuntu 24.04. Try changing your proxy_pass to be explicit:
proxy_pass http://127.0.0.1:3000;
Also check if the app is actually running after the upgrade. Ubuntu 24.04 changed some systemd defaults and services do not always survive an OS upgrade with their unit files intact:
systemctl status your-app
journalctl -u your-app --since "1 hour ago"
Your AppArmor suspicion is worth checking too:
sudo aa-status
sudo journalctl | grep apparmor | grep nginx
If AppArmor is blocking Nginx from making outbound connections, you will see denials in the journal.
The IPv6/localhost issue is the most common cause of this after an Ubuntu upgrade so start there.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Scale up as you grow — whether you're running one virtual machine or ten thousand.

From GPU-powered inference and Kubernetes to managed databases and storage, get everything you need to build, scale, and deploy intelligent applications.
