【发布时间】:2021-04-13 12:26:34
【问题描述】:
我有一个使用 nginx 设置的 Gatsby 站点。我知道 Gatsby 使用 pages/404.js 中存在的任何组件作为 404 页面。如果我导航到www.mysite.com/404,我可以看到我创建的自定义 Gatsby 404 页面,但这是我唯一一次看到 Gatsby 404 组件。如果我导航到 www.mysite.com/blahblahblah 或任何其他不存在的页面,我会看到默认的白色 nginx 404 页面。
我对 Gatsby 很熟悉,但对 nginx 却是个菜鸟。当用户导航到不存在的页面而不是显示默认的 nginx 404 页面时,如何设置我的 nginx 配置以将我的用户重定向到我的自定义 Gatsby 404 组件?
这是我的 nginx 配置:
server {
listen 80;
sendfile on;
default_type application/octet-stream;
root /usr/share/nginx/html;
location / {
try_files $uri $uri/ /index.html =404;
}
}
【问题讨论】:
标签: nginx http-status-code-404 config