NGINX入口404重定向到URI

问题描述 投票:0回答:1

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

if ($request_uri != URI) {
  proxy_intercept_errors on;
  error_page 404 URI;
}
nginx nginx-location nginx-config nginx-ingress
1个回答
0
投票

将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/'" />    
© www.soinside.com 2019 - 2024. All rights reserved.