Stuck with LEMP centos 7 (page not found)

October 10, 2014 3.2k views

Hi, I have a problem with my server, I’m using LEMP stack on centos 7, cloudflare as DNS and wordpress.
I can only access my website’s home maydara.ovh and the dashboard (maydara.ovh/wp-admin/*) but I can’t access any other page even the “Hello world!” native wordpress’s post is inaccessible all I get is “The page you are looking for cannot be found.” (I think its 404 error, correct if I'm wrong)
Somebody help me please.

2 comments
  • Could you post your configuration?

    Also, are you checking the logs to see if there's additional information?

  • Here is my nginx default.conf file:

    server {
        listen       80;
        server_name  maydara.ovh;
    
        #charset koi8-r;
        #access_log  /var/log/nginx/log/host.access.log  main;
    
            root   /usr/share/nginx/html;
            index  index.php index.html index.htm;
        location / {
            try_files $uri $uri/ =404;
        }
    
        error_page  404              /404.html;
    
        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   /usr/share/nginx/html;
        }
    
        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}
    
        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        location ~ \.php$ {
        try_files $uri =404;
        fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
        }   
        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }
    
    

    and this is my nginx error.log file:

    2014/10/10 06:24:24 [error] 2243#0: *3 FastCGI sent in stderr: "PHP message: PHP Warning:  phpinfo(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected the timezone 'UTC' for now, but please set date.timezone to select your timezone. in /usr/share/nginx/html/info.php on line 1" while reading response header from upstream, client: 141.101.98.205, server: maydara.ovh, request: "GET /info.php HTTP/1.1", upstream: "fastcgi://unix:/var/run/php-fpm/php-fpm.sock:", host: "www.maydara.ovh"
    2014/10/10 07:08:10 [warn] 2311#0: *38 an upstream response is buffered to a temporary file /var/cache/nginx/fastcgi_temp/1/00/0000000001 while reading upstream, client: 141.101.98.205, server: maydara.ovh, request: "GET /wp-admin/load-styles.php?c=0&dir=ltr&load=dashicons,admin-bar,wp-admin,buttons,wp-auth-check&ver=4.0 HTTP/1.1", upstream: "fastcgi://unix:/var/run/php-fpm/php-fpm.sock:", host: "www.maydara.ovh", referrer: "http://www.maydara.ovh/wp-admin/"
    2014/10/10 07:08:11 [warn] 2311#0: *43 an upstream response is buffered to a temporary file /var/cache/nginx/fastcgi_temp/2/00/0000000002 while reading upstream, client: 141.101.98.205, server: maydara.ovh, request: "GET /wp-admin/load-scripts.php?c=0&load%5B%5D=hoverIntent,common,admin-bar,wp-ajax-response,jquery-color,wp-lists,quicktags,jquery-query,admin-comments,jquery-ui-core,jquery-&load%5B%5D=ui-widget,jquery-ui-mouse,jquery-ui-sortable,postbox,dashboard,customize-base,customize-loader,thickbox,plugin-install,underscor&load%5B%5D=e,shortcode,media-upload,svg-painter,heartbeat,wp-auth-check,word-count,wplink&ver=4.0 HTTP/1.1", upstream: "fastcgi://unix:/var/run/php-fpm/php-fpm.sock:", host: "www.maydara.ovh", referrer: "http://www.maydara.ovh/wp-admin/"
    2014/10/10 08:31:56 [warn] 2311#0: *65 an upstream response is buffered to a temporary file /var/cache/nginx/fastcgi_temp/3/00/0000000003 while reading upstream, client: 141.101.98.205, server: maydara.ovh, request: "GET /wp-admin/load-styles.php?c=0&dir=ltr&load=dashicons,admin-bar,buttons,media-views,wp-admin,wp-auth-check&ver=4.0 HTTP/1.1", upstream: "fastcgi://unix:/var/run/php-fpm/php-fpm.sock:", host: "www.maydara.ovh", referrer: "http://www.maydara.ovh/wp-admin/post-new.php?post_type=page"
    2014/10/10 08:31:56 [warn] 2311#0: *70 an upstream response is buffered to a temporary file /var/cache/nginx/fastcgi_temp/4/00/0000000004 while reading upstream, client: 141.101.98.205, server: maydara.ovh, request: "GET /wp-admin/load-scripts.php?c=0&load%5B%5D=jquery-core,jquery-migrate,utils,plupload,json2&ver=4.0 HTTP/1.1", upstream: "fastcgi://unix:/var/run/php-fpm/php-fpm.sock:", host: "www.maydara.ovh", referrer: "http://www.maydara.ovh/wp-admin/post-new.php?post_type=page"
    2014/10/10 08:31:56 [warn] 2311#0: *65 an upstream response is buffered to a temporary file /var/cache/nginx/fastcgi_temp/5/00/0000000005 while reading upstream, client: 141.101.98.205, server: maydara.ovh, request: "GET /wp-admin/load-scripts.php?c=0&load%5B%5D=hoverIntent,common,admin-bar,schedule,wp-ajax-response,autosave,suggest,jquery-color,wp-lists,jquery-ui-core,jquery-ui-widget,jq&load%5B%5D=uery-ui-mouse,jquery-ui-sortable,postbox,heartbeat,post,editor-expand,thickbox,underscore,shortcode,backbone,wp-util,wp-backbone&load%5B%5D=,media-models,wp-plupload,mediaelement,wp-mediaelement,media-views,media-editor,media-audiovideo,wp-playlist,mce-view,imgareasel&load%5B%5D=ect,image-edit,svg-painter,wp-auth-check,word-count,editor,quicktags,wplink,wp-fullscreen,media-upload&ver=4.0 HTTP/1.1", upstream: "fastcgi://unix:/var/run/php-fpm/php-fpm.sock:", host: "www.maydara.ovh", referrer: "http://www.maydara.ovh/wp-admin/post-new.php?post_type=page"
    2014/10/10 08:32:50 [warn] 2311#0: *65 an upstream response is buffered to a temporary file /var/cache/nginx/fastcgi_temp/6/00/0000000006 while reading upstream, client: 141.101.98.205, server: maydara.ovh, request: "GET /wp-admin/load-scripts.php?c=0&load%5B%5D=hoverIntent,common,admin-bar,schedule,wp-ajax-response,autosave,jquery-color,wp-lists,quicktags,jquery-query,admin-comments,sugg&load%5B%5D=est,jquery-ui-core,jquery-ui-widget,jquery-ui-mouse,jquery-ui-sortable,postbox,heartbeat,post,editor-expand,thickbox,underscore,&load%5B%5D=shortcode,backbone,wp-util,wp-backbone,media-models,wp-plupload,mediaelement,wp-mediaelement,media-views,media-editor,media-audi&load%5B%5D=ovideo,wp-playlist,mce-view,imgareaselect,image-edit,svg-painter,wp-auth-check,word-count,editor,wplink,wp-fullscreen,media-uplo&load%5B%5D=ad&ver=4.0 HTTP/1.1", upstream: "fastcgi://unix:/var/run/php-fpm/php-fpm.sock:", host: "www.maydara.ovh", referrer: "http://www.maydara.ovh/wp-admin/post.php?post=4&action=edit&message=6"
    
2 Answers

Replace your virtualhost with the following (I deleted some of the unnecessary comments and edited the line in red):

server {
    listen       80;
    server_name  maydara.ovh;

    root   /usr/share/nginx/html;
    index  index.php index.html index.htm;
    location / {
        try_files $uri $uri/ /index.php$is_args$args =404;
    }

    # process PHP files
    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }   

    # deny access to .*
    location ~ /\. {
        deny  all;
    }
}

and restart nginx: sudo service nginx restart. Does that work?

  • @kamaln7 Thank you for responding mate, but now I'm getting some sort of *.bin files when I try to access any page instead of 404 errors.

  • Sorry, delete $is_args$args:

    server {
        listen       80;
        server_name  maydara.ovh;
    
        root   /usr/share/nginx/html;
        index  index.php index.html index.htm;
        location / {
            try_files $uri $uri/ /index.php =404;
        }
    
        # process PHP files
        location ~ \.php$ {
            try_files $uri =404;
            fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include fastcgi_params;
        }   
    
        # deny access to .*
        location ~ /\. {
            deny  all;
        }
    }
    
  • I'm sorry its still the same issue.
    P.S. i'm on centos 7 with nginx 1.6.2

  • That's odd. Are there any errors in nginx's error log?

    sudo tail -30 /var/log/nginx/error.log
    

    Try clearing Cloudflare's cache, does that fix it?

  • My error log is empty because yesterday I've rebooted my droplet and cloudflare's cache is now purged but I'm still stuck with same issue :(

Hi guys!
on my server cents 7 have the probably the same problem.....
from nginx/error.log
2014/12/10 23:14:25 [error] 3031#0: *1 FastCGI sent in stderr: "Unable to open primary script: /scripts/test.php (No such file or directory)" while reading response header from upstream, client: 192.168.0.102, server: 192.168.0.150, request: "GET /test.php HTTP/1.1", upstream: "fastcgi://unix:/var/run/php-fpm/php-fpm.sock:", host: "192.168.0.150"

here is the nginx/default.conf
<^> server {
listen 80;
server_name 192.168.0.150;

#charset koi8-r;
#access_log  /var/log/nginx/log/host.access.log  main;

location / {
    root   /usr/share/nginx/html;
    index index.php index.html index.htm;
}

error_page  404              /404.html;

# redirect server error pages to the static page /50x.html
#
error_page   500 502 503 504  /50x.html;
location = /50x.html {
    root   /usr/share/nginx/html;
}

# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
# location ~ \.php$ {
#    proxy_pass   http://127.0.0.1;
#}
#pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000

location ~ .php$ {
root /usr/share/nginx/html;
fastcgiindex index.php;
fastcgi
pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgiparam SCRIPTFILENAME /scripts$fastcgiscriptname;
include fastcgi_params;
}

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
#    deny  all;
#}

}<^>

any ideas?

Have another answer? Share your knowledge.