en
  English
Phone:  +370 (5) 204-1903
Skype:  onegbits
  1. Home
  2. Blog
  3. How To Fix 502 Bad Gateway Error on Nginx

How To Fix 502 Bad Gateway Error on Nginx

26

Sep, 16

1481

How To Fix 502 Bad Gateway Error on Nginx? 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
To:
listen = 127.0.0.1:9000
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.sock
How To Fix 502 Bad Gateway Error on Nginx Save
Adrian Lawrence

2018 May 16, 06: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