Nginx – Error 404 with WordPress subdomain using nginx

nginxPHPphp-fpmphp7Wordpress

I'm in the process of setting up a subdomain with wordpress on it. I'm getting a 404 error with my nginx configuration. Currently using PHP Version: 7.0.22, not getting any errors in the php logs, but I am in nginx

/var/log/nginx/error.log

 *1 open() "/usr/share/nginx/html/50x.html" failed (2: No such file or directory), client: xxx.xxx.xxx.xxx, server: kb.workspire.io, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/var/run/php7-fpm.sock", host: "kb.workspire.io"

Here is my current server block

/etc/nginx/sites-available/kb.workspire.io

server {
    listen 80
    server_name kb.workspire.io;
    root /var/www/kb.workspire.io/wordpress;
    index index.php;

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

    listen 443 ssl;

    error_page 404 /404.html;

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

    location ~ \.php$ {
            try_files $uri =404;
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_pass unix:/var/run/php7-fpm.sock;
            fastcgi_index index.php;
            include fastcgi_params;
    }

Best Answer

The location block here:

location = /50x.html {
        root /usr/share/nginx/html;
}

is telling nginx to fetch a custom error page /usr/share/nginx/html/50x.html which is then throwing an error because it doesn't exist.

If you are using custom error pages, you'll want to fix your paths so they can be found. It certainly looks odd that the 50x.html page is expected to be in /usr/share/nginx/html but the 40x.html page is looking in /var/www/kb.workspire.io/wordpress.

If you are not using custom error pages, you can remove the error_page directives and the location = /50x.html block.