如何让 hugo 服务器使用自定义 404.html

How to make hugo server use custom 404.html

文档页面 https://gohugo.io/templates/404/#automatic-loading

hugo 服务器不会自动 加载您的自定义 404.html 文件,但您可以通过以下方式测试自定义“未找到”页面的外观将浏览器导航至 /404.html.

问题: 有没有办法显式配置 hugo 服务器使用自定义 404 页面?

这是不可能的。 Hugo 只会产生一个静态网站。您必须在生产环境中使用 Web 服务器 而不是 Hugo 的开发服务器。

Hugo 不应该实施任何类型的 API。这不是它的目的。我用了很长时间的 Hugo,从来不需要 Hugo 的这些功能。

如果您能够 运行 hugo serve 在服务器上,那么您也可能能够安装软件包。您应该使用 nginx、apache 或 w/e 您觉得最适合生产环境的产品。

大量在线教程:

  1. https://www.digitalocean.com/community/tutorials/how-to-install-nginx-on-ubuntu-18-04
  2. https://www.digitalocean.com/community/tutorials/how-to-configure-nginx-to-use-custom-error-pages-on-ubuntu-14-04

它真的没有那么难,而且在漫长的 运行 中会让你省去很多麻烦。如果您需要一些东西来快速向其他人展示您的站点(因为在 public 面向计算机 上使用 hugo 的开发服务器时通常会出现这种情况)请尝试 https://ngrok.com/