nginx+php5-fpm .php Pages not reflecting changes

CRK asked:

I’m very experienced with Apache, but I wanted to make the switch to Nginx to try and gain experience with a very popular piece of software. Unfortunately I have not gotten very far and this problem is driving me crazy.

After putting up a test page (just a simple): echo “This is Nginx”;

I decompressed my .tar.gz file and loaded all the web files into the directory – I check the permissions too, btw. Unfortunately all I can see is still “This is Nginx”

Thus far I have:

  • Restarted Nginx
  • Restarted php5-fpm (yes, I know there are several ways for different systems, I tried them all)
  • Made sure the file permissions are correct
  • Reviewd my config files and server block (see below) and,
  • Turned off the sendfile option in nginx.conf

My server block looks as follows:

server {
    listen   80;
    server_name xxx;
    access_log  /var/log/nginx/localhost.access.log;

## Default location
location / {
    root   /srv/www;
    index  index.php;
}

## Images and static content is treated different
location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico|xml)$ {
  access_log        off;
  expires           30d;
  root /srv/www;
}

## Parse all .php file in the /var/www directory
location ~ [^/].php(/|$) {
    fastcgi_split_path_info ^(.+?.php)(/.*)$;
    if (!-f $document_root$fastcgi_script_name) {
            return 404;
    }
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_index index.php;
    include fastcgi_params;
}

## Disable viewing .htaccess & .htpassword
location ~ /.ht {
    deny  all;
}
}

My nginx.conf file is the same as the default, less the SendFile change pointed out above. Any help someone can offer would be much appreciated.

My answer:


You forgot to declare root within your server block. You only have it repeated in some location blocks. This is one of the most common nginx misconfigurations. Move them out to the server block.


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.