Wordpress and nginx all pages works fine except for non-existent .php

Posted December 9, 2020 303 views

I configured my WordPress website on Nginx and everything works fine but for non-existent .php pages Those return the nginx default 404 page not found why ?

location / {
#try_files $uri $uri/ =404;

    try_files $uri $uri/ /index.php$is_args$args;


location ~ .php$ {
include snippets/fastcgi-php.conf;

            # With php7.4-fpm:
            fastcgi_pass unix:/run/php/php7.4-fpm.sock;

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
1 answer

Hi @mhcoding1,

You can configure a custom 404 page if you wish. You can follow this DigitalOcean tutorial :

Don’t mind it’s old, you can still reuse the code from the server blocks such as

        error_page 500 502 503 504 /custom_50x.html;
        location = /custom_50x.html {
                root /usr/share/nginx/html;

        location /testing {
                fastcgi_pass unix:/does/not/exist;


by Justin Ellingwood
Nginx is a high performance web server capable of serving content with flexibility and power. When designing your web pages, it is often helpful to customize every piece of content that your users will see. This includes error pages for when they request content that is not...