简体   繁体   中英

NGINX Ingress 404 redirect to URI

I want to redirect all my 404s to another 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. 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. 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):

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

and at custom_404.html file

use any redirect like

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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