Nginx returning 404 for virtual server

December 24, 2014 554 views

Running Nginx on CentOS 7.
Here's my server conf.

server {
listen 80;

    access_log  /home/bao/logs/  main;
    error_log  /home/bao/logs/ error;

    root /home/bao/www/;
    index  index.php index.html index.htm;

    location / {
        root   /home/bao/www/;
        if (!-e $request_filename){
          rewrite ^/(.*)$ /index.php?q=$1 last;

    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/local/www/nginx-dist;

   # pass the PHP scripts to FastCGI server listening on
    location ~ \.php$ {
        root /home/bao/www/;
        fastcgi_index  index.php;
        fastcgi_split_path_info ^(.+\.php)(.*)$;
        fastcgi_param  SCRIPT_FILENAME  $document_root/$fastcgi_script_name;
        include        fastcgi_params;
        fastcgi_ignore_client_abort on;
        fastcgi_param SERVER_NAME $http_host;

    location ~ /\.ht {
        deny  all;


But when I try to access the server it returns error 404. The files are in place and as far as I can see are accessible.

Be the first one to answer this question.