You are not logged in.

#1 2014-03-08 15:01:50

psycho_tea_drinker
Member
From: West Sussex, United Kingdom
Registered: 2013-07-02
Posts: 41

Serving .php files gives 502 Bad Gateway with Nginix + PHP-fpm

I've been struggling with this for most of the afternoon.... Arrrrrrrghhh

First of all the nginx error log is empty. The access log shows nothing out of the ordinary:

127.0.0.1 - - [08/Mar/2014:14:43:28 +0000] "GET /index.php HTTP/1.1" 502 172 "-" "Mozilla/5.0 (X11; Linux i686; rv:27.0) Gecko/20100101 Firefox/27.0"

php-fpm's error log isn't appending anything on a request / error ethier.

Here is my nginx.conf file:

worker_processes  1;
error_log  logs/error.log  info;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;

    server {

        server_name $http_host;
        root /home/webroot/$http_host;
        autoindex on;

        index index.php index.html index.htm;

        location ~* \.(jpg|jpeg|gif|css|png|js|ico|html)$ {
            access_log off;
            expires max;
        }

        location ~ \.php$ {
            try_files $uri =404;
            fastcgi_pass unix:/var/run/php5-fpm.sock;
            fastcgi_index index.php;
            include fastcgi_params;
        }
    }
}

Can somebody please tell me how I can get more info as to which file nginix is trying to process etc? It's so frustrating!

Offline

#2 2014-03-09 21:20:32

Centzilius
Member
From: Berlin, Germany
Registered: 2014-03-09
Posts: 14
Website

Re: Serving .php files gives 502 Bad Gateway with Nginix + PHP-fpm

Try replacing the following line:

fastcgi_pass unix:/var/run/php5-fpm.sock;

with this one

fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;

and make sure php-fpm is running (systemctl start php-fpm).

--EDIT:
Let's explain it.
The response 502 Bad Gateway is a result of nginx not being to communicate with php-fpm in this case. The php-fpm.sock is normaly located in /var/run/php-fpm/ and not in /var/run directly and it is not named php5-fpm.sock (I think thats the name in Debian).

With kind regards
Centzilius
PS: Please excuse my poor english skills (I'm not a native speaker)

Last edited by Centzilius (2014-03-09 21:27:51)


PGP-Key: BEF72880 - Website
Please excuse my poor English skills. I'm not a native speaker.

Offline

#3 2014-03-11 20:32:07

psycho_tea_drinker
Member
From: West Sussex, United Kingdom
Registered: 2013-07-02
Posts: 41

Re: Serving .php files gives 502 Bad Gateway with Nginix + PHP-fpm

Centzilius wrote:

Try replacing the following line:

fastcgi_pass unix:/var/run/php5-fpm.sock;

with this one

fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;

and make sure php-fpm is running (systemctl start php-fpm).

--EDIT:
Let's explain it.
The response 502 Bad Gateway is a result of nginx not being to communicate with php-fpm in this case. The php-fpm.sock is normaly located in /var/run/php-fpm/ and not in /var/run directly and it is not named php5-fpm.sock (I think thats the name in Debian).

With kind regards
Centzilius
PS: Please excuse my poor english skills (I'm not a native speaker)

Indeed I copied it from a linux mint system.

I've changed that line and it now gives me a blank page. (No output in nginix error log or php-fpm log). However the access log shows a request with a 200 response code:

127.0.0.1 - - [11/Mar/2014:20:30:56 +0000] "GET /index.php HTTP/1.1" 200 5 "-" "Mozilla/5.0 (X11; Linux i686; rv:27.0) Gecko/20100101 Firefox/27.0"

Offline

#4 2014-03-11 20:34:55

psycho_tea_drinker
Member
From: West Sussex, United Kingdom
Registered: 2013-07-02
Posts: 41

Re: Serving .php files gives 502 Bad Gateway with Nginix + PHP-fpm

Success!!!

One more change was needed

include fastcgi_params;

to

include fastcgi.conf;

Thank you Centzilius!

Offline

#5 2014-03-14 15:51:35

Centzilius
Member
From: Berlin, Germany
Registered: 2014-03-09
Posts: 14
Website

Re: Serving .php files gives 502 Bad Gateway with Nginix + PHP-fpm

You're welcome


PGP-Key: BEF72880 - Website
Please excuse my poor English skills. I'm not a native speaker.

Offline

Board footer

Powered by FluxBB