繁体   English   中英

NGINX 入口 404 重定向到 URI

[英]NGINX Ingress 404 redirect to URI

我想将所有 404 重定向到另一个 URI。 问题是我的其他 URI 的响应代码为 404。因此,当我使用error_page 404 URI时,重定向会循环发生。 示例服务器片段如下所示

if ($request_uri != URI) {
  proxy_intercept_errors on;
  error_page 404 URI;
}

将 404 错误定向到自定义 404 页面 使用 error_page 指令,以便在发生 404 错误时(未找到请求的文件时)提供您创建的自定义页面。 我们将为文件创建一个位置块,在这里我们能够确保根与我们的文件系统位置匹配,并且该文件只能通过内部 Nginx 重定向访问(客户端不能直接请求):

error_page 404 /custom_404.html;
    location = /custom_404.html {
            root /usr/share/nginx/html;
            internal;
    }

并在 custom_404.html 文件中

使用任何重定向,如

<meta http-equiv="refresh" content="0;URL='http://thetudors.example.com/'" />    

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM