简体   繁体   English

NGINX 入口 404 重定向到 URI

[英]NGINX Ingress 404 redirect to URI

I want to redirect all my 404s to another URI.我想将所有 404 重定向到另一个 URI。 The problem is that my other URI has a response code of 404. So when I use error_page 404 URI , the redirection occurs in a loop.问题是我的其他 URI 的响应代码为 404。因此,当我使用error_page 404 URI时,重定向会循环发生。 Example server snippet is shown below示例服务器片段如下所示

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

Direct 404 Errors to the Custom 404 Page Use the error_page directive so that when a 404 error occurs (when a requested file is not found), the custom page you created is served.将 404 错误定向到自定义 404 页面 使用 error_page 指令,以便在发生 404 错误时(未找到请求的文件时)提供您创建的自定义页面。 We will create a location block for the file, where we are able to ensure that the root matches our file system location and that the file is only accessible through internal Nginx redirects (not requestable directly by clients):我们将为文件创建一个位置块,在这里我们能够确保根与我们的文件系统位置匹配,并且该文件只能通过内部 Nginx 重定向访问(客户端不能直接请求):

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

and at custom_404.html file并在 custom_404.html 文件中

use any redirect like使用任何重定向,如

<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