Installing nginx + php-fpm – got Not found

Medvedev asked:

I install nginx and php-fpm on new machine. But when i open my domain, i got an 404 Not Found. (static files accessible).

File: /etc/nginx/sites-available/elfchat.net

server {
    listen   80;
    server_name www.elfchat.net elfchat.net;
    access_log /home/user/site.net/logs/access.log;
    error_log /home/user/site.net/logs/error.log;

    location / {
        root   /home/user/site.net/www;
        index  index.php;
    }

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

        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    }
}

Where to look to find why this does not working? Thanks!

May be it’s it file permissions?

$ ls -la ~
drwxr-xr-x 4 user user    4096 Jul  1 19:19 .
drwxr-xr-x 3 root  root     4096 Jul  1 17:19 ..
-rw------- 1 user user    2589 Jul  1 20:01 .bash_history
-rw-r--r-- 1 user user     220 Jul  1 17:19 .bash_logout
-rw-r--r-- 1 user user    3392 Jul  1 17:19 .bashrc
drwxrwsr-x 4 user www-data 4096 Jul  1 18:18 site.net
-rw-r--r-- 1 user user     675 Jul  1 17:19 .profile
drwx------ 2 user user    4096 Jul  1 17:27 .ssh

$ ls -la ~/site.net/www/
drwxr-xr-x 2 user www-data 4096 Jul  1 19:24 .
drwxrwsr-x 4 user www-data 4096 Jul  1 18:18 ..
-rwxr-xr-x 1 user www-data   17 Jul  1 19:21 index.php

My answer:


You have at least two obvious problems here.

First, you didn’t define a root in your server block. You instead misplaced it in one of the location blocks. This is one of the most common nginx misconfigurations.

Second, you have a typo in one of your try_files statements. = 404 should be =404.


View the full question and answer on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.