Php – Nginx stating “502 Bad Gateway”

nginxPHPvagrant

Ok, I'm running an app locally as homestead.app:8000. I am running Vagrant and this only started happening after I did "vagrant halt" to change the document root for Nginx and then vagrant up.

Nginx is returning 502 Bad Gateway to the browser and the error log for my test domain states the following:

2014/05/18 21:37:11 [crit] 1368#0: *7 connect() to unix:/var/run/php5-fpm.sock failed (2: No such file or directory) while connecting to upstream, client: 10.0.2.2, server: homestead.app, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/var/run/php5-fpm.sock:", host: "homestead.app:8000"

Best Answer

Make sure php-fpm is running. I had similar issue so at the end I changed default php-fpm port from 9000 to 8999 and kicked out socket info from nginx.conf file (replaced with host and port number). In my case this was working:

location ~ \.php {
        fastcgi_pass 127.0.0.1:8999;
        fastcgi_index /index.php;

        include /usr/local/etc/nginx/fastcgi_params;

        fastcgi_split_path_info       ^(.+\.php)(/.+)$;
        fastcgi_param PATH_INFO       $fastcgi_path_info;
        fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_read_timeout 600;
    }
Related Topic