Phone :  +370 (5) 204-1903
Email: sales@1gbits.com
  1. Dedicated server
  2. Blog
  3. How To Fix 502 Bad Gateway Error on Nginx
How To Fix 502 Bad Gateway Error on Nginx


Sep, 16

A 502 error, which is most commonly referred to as “Bad Gateway Error” is generally caused due to timeout of PHP request. A gateway is an access point or bridge that establishes a connection between two services. In order to prevent this error, you need to adjust some server settings i.e. you can increase “Execution Limit” from server settings, by following this article.

How To Fix 502 Bad Gateway Error on Nginx

Method 1. Changes in Nginx Config

#nano /etc/nginx/nginx.conf
http {
    fastcgi_buffers 8 16k;
    fastcgi_buffer_size 32k;

Method 2. change PHP-FPM to listen on a unix socket or TCP socket.

#nano /etc/php-fpm.d/www.conf
listen = /var/run/php5-fpm.sock
listen =

If you are configuring php-fpm to listen on a Unix socket, you should also check that the socket file has the correct owner and permissions.

chmod 0660 /var/run/php5-fpm.sock
chown www-data:www-data /var/run/php5-fpm.sockSave
author img


Generic placeholder image
Adrian Lawrence

2018 May 16, 10:05:36

If you don't run caching then that often makes a big difference, for example using Varnish Cache, the underlying issue is like to be server bottlenecks.

Leave A Comment