簡體   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