Nginx + WordPress 404 pages, all works but .php files
I configured my WordPress website on Nginx and almost everything works as expected. I get the WordPress 404 for every non-existent page as expected -- except for non-existent .php pages! Those return the nginx default 404 page not found. Why is this? I would like to get the WordPress 404.
Thanks! This is the config file:
set $skip_cache 0;
if ($request_method = POST) {
set $skip_cache 1;
}
if ($query_string != "") {
set $skip_cache 1;
}
if ($request_uri ~* "/wp-admin/|/xmlrpc.php|wp-.*.php|/feed/|index.php|sitemap(_index)?.xml") {
set $skip_cache 1;
}
if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_no_cache|wordpress_logged_in") {
set $skip_cache 1;
}
location ~ /purge(/.*) {
fastcgi_cache_purge MYWP "$scheme$request_method$host$1";
}
location @php {
try_files $uri =404;
add_header X-Cache $upstream_cache_status;
include /etc/nginx/fastcgi_params;
####
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_script_name;
fastcgi_cache latigreelacrobata.lanavediteseo.eu;
fastcgi_cache_bypass $skip_cache;
fastcgi_no_cache $skip_cache;
fastcgi_cache_valid 200 60m;
fastcgi_intercept_errors on;
fastcgi_buffer_size 128k;
fastcgi_buffers 256 16k;
fastcgi_busy_buffers_size 256k;
fastcgi_temp_file_write_size 256k;
fastcgi_read_timeout 240;
}
location / {
index index.php index.html index.htm;
try_files $uri $uri/ /index.php?$args;
}
rewrite /wp-admin$ $scheme://$host$uri/ permanent;
location ~* ^.+\.(css|js|ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|rss|atom|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$ {
access_log off; log_not_found off; expires max;
}
You have the following lines in your configuration:
location @php {
try_files $uri =404;
Its says that, if a php file is not found, nginx will throw its own 404 page.
If you want Wordpress to deal with 404 also in those cases, replace it by:
location @php {
try_files $uri $uri/ /index.php?$args;
This will direct the request to Wordpress, and it will show your desired 404 page.