Skip to Content

502 on login with nginx

ERROR: 502 bad gateway error


Overview:  This article describes steps to resolve a 502 Bad Gateway error in nginx by adjusting buffer sizes in nginx.conf and restarting the nginx service.


If you're encountering a 502 Bad Gateway error on Ubuntu and need to adjust nginx settings, follow these steps:

Step 1: Edit nginx.conf:

Open the nginx main configuration file with a text editor. Add the following in nginx.conf:

root@gateway:~# nano /etc/nginx/nginx.conf

proxy_buffer_size 128k;      

proxy_buffers 4 256k;      

proxy_busy_buffers_size 256k;

Step 2: Edit the " \.php$ " section in nginx.conf:

Locate the \.php$ section within nginx.conf. This section typically handles PHP requests. Add the following configuration directives to the " \.php$ " location block.

fastcgi_buffer_size 128k;
fastcgi_buffers 4 256k;
fastcgi_busy_buffers_size 256k;

Step 3: Restart nginx:

After saving the changes, restart nginx to apply the configuration

root@gateway:~# systemctl restart nginx

These steps ensure that you've properly adjusted the buffer sizes in nginx.conf and restarted nginx to resolve the 502 Bad Gateway error.

Adjust paths ( /etc/nginx/nginx.conf) according to your actual nginx configuration file location if it differs.

Feel free to take the help of support if you encounter any issues or need further assistance!


Related Articles: 

Configure nginx web server on the Jump server

404 error on login with nginx

Self-signed SSL for nginx in Debian