Customize 404.html when using hugo server

I had already setup the 404.html page in the layouts folder, but when using hugo server as a quick http web server. It always did not work. There is always showing “404 page not found”.

I know I could use hugo build the static pages in public and rendered by nginx apache. But I just want to use hugo server as a very simple fast http web server solution. Could someone tell me how to make the layouts/404.html work when using hugo server ?

The reason the 404 layout can be set is because web servers like Apache and nginx can be configured to serve a page when they serve a 404 error code. You and I may think that a 404 page makes good, human sense, but it is really tacked on to a web server handling error codes.

That is why when you using Apache, et al., you have to tell the web server explicitly to serve that 404.html on 404 errors.

The hugo web server is not a robust web server, it’s focus is to render the site for development. So unless someone does a really great patch that doesn’t conflict with other parts of the app, I doubt 404 page serving will be added. :slight_smile:

Currently, Hugo’s built-in server doesn’t handle 404 errors. There is an open issue on GitHub about this feature:

https://github.com/gohugoio/hugo/issues/874

It is a very simple static file server built on standard Go built-in functions, so it is very robust, but you are right – it is a development/preview server, so it will never get the “advanced features”.

Understood that, but I strongly recommend hugo server could consider this feature. We shouldn’t just restrict hogo server as the develop/preview server. We may add some plugin mechanism to customize it to make it robust enough, or allow 3th light weight Go web server to be integrated into Hugo.

Hugo creates static web pages, it will integrate with every web server.

If you want to develop your 404.html, just point the URL directly to it. I’m not sure of the added benefit of pointing to a stylized 404 page to represent broken links on local dev…

If you’re looking for a cool web server project written in Golang, btw, check out Caddy:

1 Like

That make sense, caddy is quite cool and light enough. Thanks a lot!