Austin DeVinney
Austin DeVinney

Reputation: 273

Nginx with PHP5-FPM -- .php files giving blank screens

I'm banging my head against the wall trying to get nginx up and running with php5-fpm. I felt that it was a small detail I was overlooking, so I took a break and came back to it a few days later. Been messing with it for another few hours tonight to no avail.

Anyways, here is the issue: I have nginx up and running. It appears to be serving out web pages properly. for example, the base website of http://www.shidenadvanced.com serves up just fine. However, the php test I have, located at http://www.shidenadvanced.com/test.php is coming back as blank. Previously it was coming back as a 502 Bad Gateway.

Through my research I was lead to understand that meant it could not properly route it through the php-fpm. Not 100% on that.

This is my /sites-available/config:

server {
    server_name www.shidenadvanced.com shidenadvanced.com;
    access_log /srv/sites/shidenadvanced/logs/access.log;
    error_log /srv/sites/shidenadvanced/logs/error.log;

    root /srv/sites/shidenadvanced/www;
    index index.php index.html index.htm;

    location / {
        try_files $uri $uri/ /index.html;
    }

    #location ~ \.php$ {
    #    try_files $uri =404;
    #    include /etc/nginx/fastcgi_params;
    #    fastcgi_pass unix:/var/run/php-fpm5.sock;
    #    fastcgi_index index.php;
    #    fastcgi_param SCRIPT_FILENAME /srv/sites/shidenadvanced/www$fastcgi_script_name;
    #}

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

    location ~ /\.ht {
        deny all;
    }
}

Outside of this I have left most of the settings alone. Not entirely sure what's going on. Can anyone shed some light?

Upvotes: 3

Views: 9380

Answers (2)

Jens Peters
Jens Peters

Reputation: 2161

I am personally prefer the socket solution:

fastcgi_pass unix:/path/tp/myfirst.socket;

instead of

fastcgi_pass 127.0.0.1:9000;

but you need an fpm config for the host too:

[hak-rentrisch_de]
listen = /path/tp/myfirst.socket
listen.owner = hostuser
listen.group = hostgroup
listen.mode = 0666

listen.backlog = -1
listen.allowed_clients = 127.0.0.1

user = hostuser
group = hostgroup

pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
pm.max_requests = 500

php_admin_value[include_path] = .:/var/www/libs 
[...]

Kind regards

Upvotes: 2

ipengineer
ipengineer

Reputation: 3307

Try this. I made a few changes to the way you are handling fastcgi

server {
server_name www.shidenadvanced.com shidenadvanced.com;
access_log /srv/sites/shidenadvanced/logs/access.log;
error_log /srv/sites/shidenadvanced/logs/error.log;

root /srv/sites/shidenadvanced/www;
index index.php index.html index.htm;

location / {
    try_files $uri $uri/ /index.html;
}

# use fastcgi for all php files
location ~ \.php$
{
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
}

location ~ /\.ht {
    deny all;
}
}

Upvotes: 2

Related Questions