502 Gateway Error on nginx Running a Laravel App

October 23, 2015 3.5k views
PHP Nginx PHP Frameworks Ubuntu

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.

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

  • Here are my config files:

    /etc/php5/fpm/pool.d/www.conf

    [www]
    
    user = www-data
    group = www-data
    listen = /var/run/php5-fpm.sock
    listen.owner = www-data
    listen.group = www-data
    
    pm = dynamic
    pm.maxchildren = 5
    pm.startservers = 2
    pm.minspareservers = 1
    pm.maxspareservers = 3
    chdir = /
    
    

    /etc/nginx/sites-enabled/default

    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/
        server_name mydomainhere.com;
        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;
        }
    }
    
1 Answer
Have another answer? Share your knowledge.