1

I've set up a LEMP environment on an Ubuntu 16.04 machine, following the How To Install WordPress with LEMP on Ubuntu 16.04 tutorial on DigitalOcean's community archive. All works great, except for when navigating to page that doesn't exist (e.g: https://www.example.com/page-that-doesnt-exist/), it returns a 200 and renders the homepage (without a 301 redirect), instead of returning a 404. However, when navigating to a page under the /blog/ scope that doesn't exist, then a 404 is returned as you'd expect (e.g: https://www.example.com/blog/post-that-doesnt-exist/).

This wouldn't be intended WordPress behaviour, right?

Below is the Nginx configuration used:

# Virtual Host configuration for www.example.com

# You can move that to a different file under sites-available/ and symlink that
# to sites-enabled/ to enable it.

server { # Redirect http:// to https://
        listen 80;
        listen [::]:80;

        server_name example.com www.example.com;

        return 301 https://www.example.com$request_uri;
}

server {
        listen 443 ssl;
        listen [::]:443 ssl;

        server_name example.com www.example.com;

        ssl_certificate     /etc/nginx/ssl/example.com.au/ssl-bundle.crt;
        ssl_certificate_key /etc/nginx/ssl/example.com/example.com.key;

        root /var/www/www.example.com;

        index index.php index.html;

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

        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 max;
                log_not_found off;
        }

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

        location ~ /\.ht {
                deny all;
        }
}
simonlehmann
  • 340
  • 1
  • 4
  • 14
  • No, that's not normal. But it's also not usually a problem with nginx. And your config looks fine. Disable all your plugins and switch to a default theme. – Michael Hampton Mar 17 '19 at 05:18
  • Thanks for your feedback. I've tried disabling all the plugins, and switching back to a clean installation of the Twenty Nineteen theme, and no improvement. Would there be anything else I could test? Thanks again. – simonlehmann Mar 23 '19 at 14:13

1 Answers1

0

The nginx configuration shared by you doesn't have any problem. Please check the wordpress configuration once for the 404 page settings.

  • Thanks for your response. I don't see any settings specific to the handling of 404 errors in the WordPress options. Is there a set of settings in particular you have in mind? Thanks again. – simonlehmann Mar 23 '19 at 14:14