502 Gateway Error on nginx Running a Laravel App

I’m reaching out to see if anyone out there might be able to offer a little insight into an odd issue one of my sites is encountering.

I set up a Laravel project on a Droplet (1GB Ram 30GB SSD Disk New York 3 Ubuntu 14.04 x64). The Droplet is running several sites under a few subdomains.

At 6 PM EST two days ago we started throwing 502 bad gateway response on one of the Laravel sites. All the other subdomains on that Droplet appeared to be working as expected.

I created a new Droplet and moved the offending Laravel project to it. It’s 2GB Ram 40GB SSD Disk same OS. At 7 PM EST yesterday we started throwing 502 bad gateway again on the new Droplet.

In both cases running “service php5-fpm restart” seemed to resolve the issue. Network traffic and CPU consumption were relatively low and dropped off when we started throwing errors, Memory consumption jumped slightly.

I’m reaching out to you to see if anyone has experienced anything similar and if there is a solution out there.


Here are my config files:



user = www-data
group = www-data
listen = /var/run/php5-fpm.sock
listen.owner = www-data = www-data

pm = dynamic
pm.maxchildren = 5
pm.startservers = 2
pm.minspareservers = 1
pm.maxspareservers = 3
chdir = /


server {
listen 80 defaultserver;
listen [::]:80 defaultserver ipv6only=on;

    root /var/www/default;
    index index.php index.html index.htm;

    # Make site accessible from http://localhost/
    error_log /var/www/default/error.log;

    location / {
            try_files $uri $uri/ /index.php$is_args$args;

    # pass the PHP scripts to FastCGI server listening on /var/run/php5-fpm.sock
    location ~ \.php$ {
            try_files $uri /index.php =404;
            fastcgi_pass unix:/var/run/php5-fpm.sock;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include fastcgi_params;

Please post your /etc/php5/fpm/pool.d/www.conf and /etc/nginx/sites-enabled/default config files.

Submit an 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.


It sounds like that your PHP-FPM service is crashing. This is most likely due to out of memory.

I would recommend adjusting your PHP memory limit so that it is not too high and maybe also adding some more RAM.

You could also check your access logs and make sure that there’s no malicious activity going on.

Finally what you could do is optimize your site so that it uses fewer resources.

Regards, Bobby

This comment has been deleted