Skip to content

Troubleshooting 502 Bad Gateway in NGINX

NGINX · Self-help guide

A 502 Bad Gateway error usually means NGINX received the visitor’s request, but the backend service it tried to contact did not respond properly. This is common when NGINX is used as a reverse proxy for Laravel, Node.js, PHP-FPM, Docker containers, dashboards, or streaming services.

Step 1: Test the NGINX configuration:

sudo nginx -t

If there is a syntax error, fix that first.

Step 2: Check the NGINX error log:

sudo tail -f /var/log/nginx/error.log

Look for messages such as connection refused, upstream timed out, no live upstreams, or permission denied.

Step 3: Confirm the backend service is running. For example:

sudo systemctl status php8.3-fpm sudo systemctl status node-app docker ps

Step 4: Check the backend port locally:

curl -I http://127.0.0.1:3000

If this fails, the problem is probably the application, not NGINX.

Step 5: Confirm your proxy_pass value matches the real backend address. If your app listens on port 3000 but NGINX proxies to 3001, you will get a 502.

Step 6: Check socket permissions if you use PHP-FPM sockets. NGINX must be able to read the socket file.

Useful commands:

sudo ss -tulpn sudo journalctl -u nginx —no-pager -n 100 sudo journalctl -u php8.3-fpm —no-pager -n 100

A 502 is frustrating, but it is also useful because it tells you NGINX is at least receiving traffic. Focus on the upstream application, service status, port, socket, and logs. Fix the backend first, then reload NGINX.

Did this solve it?If not, Penny and the support team are ready to help.Start live chatOpen a ticket