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;
}
}
The nginx configuration shared by you doesn't have any problem. Please check the wordpress configuration once for the 404 page settings.