Report this

What is the reason for this report?

Custom Wordpress 404 page not loading, Nginx 404 page loading instead.

Posted on April 29, 2020

I’m not sure why, but my custom Wordpress 404 page will not load with an improper URL that should 404, instead, the default Nginx 404 page loads. All pages are working as expected, I just want a 404 to be my 404, not the default. I’ve tried changing my permalinks just to update them, no luck. I suspect it has to do with my sever block, any ideas?

server {
        # The below listen is moved / contained in a server block down below, controlled by CertBot.
        # Only ONE default_server is allowed.
        # listen 80 default_server;
        # listen [::]:80 default_server;

        root /var/www/porterbytes.com/html;
        index index.php index.html index.htm index.nginx-debian.html;

        server_name porterbytes.com www.porterbytes.com;

        location / {
            #try_files $uri $uri/ =404;
            try_files $uri $uri/ /index.php?$args =404;
        }

        location ~ \.php$ {
            include snippets/fastcgi-php.conf;
            fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
        }

        location ~ /\.ht {
            deny all;
        }

        location = /favicon.ico { log_not_found off; access_log off; }
        location = /robots.txt { log_not_found off; access_log off; allow all; }
        location ~* \.(css|gif|ico|jpeg|jpg|js|png)$ {
            expires 7d;
            add_header Cache-Control "public, no-transform";
            log_not_found off;
        }


    listen [::]:443 ssl ipv6only=on; # managed by Certbot
    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/porterbytes.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/porterbytes.com/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot


}
server {
    if ($host = www.porterbytes.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


    if ($host = porterbytes.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


        listen 80 default_server;
        listen [::]:80 default_server;

        server_name porterbytes.com www.porterbytes.com;
    return 404; # managed by Certbot




}

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Start building today

From GPU-powered inference and Kubernetes to managed databases and storage, get everything you need to build, scale, and deploy intelligent applications.