Custom 404 error page for Nginx container

I have the container running and serving my web pages. However, when I enter the URL of a non-existent page, I get the home page (i.e., /index.html). How can I have 404 errors display a custom error page (e.g., /errors/404.html)?

I’ve tried adding the following to the /nginx/nginx.conf and/or /nginx/site-confs/default and restarting the container, but there’s no change:

    error_page 404 /errors/404.html;
    location = /errors/404.html {
            root /config/www;
            internal;
    }

Am I missing something? Thanks in advance for any help/feedback.

Found a solution! I’m posting it here in case anyone else comes looking (most likely me in the future) :smile:

In /nginx/site-confs/default, look for the following line:

try_files $uri $uri/ /index.html /index.php?$args =404;

The server will try each option in left-to-right order to resolve the page it should return (i.e., URL as typed, URL with a trailing slash, html homepage, php homepage). To use a custom 404 page, put its path between “$uri/” and “/index.html”. For example:

try_files $uri $uri/ /404.html /index.html /index.php?$args =404;

Hope this helps.