nginx-301, 302 redirect

301 permanent redirection (caching allowed)
302 temporary redirection (caching prohibited)

Configuration (return defaults to 302)

server {
    
    
    listen        8084;
    root          /data/nginx/domain5;
    server_name   www.b.com;
    location      /   {
    
    
        root          /data/nginx/domain5;
        autoindex     on;
    }
    location      /abc.html   {
    
    
        return    http://www.baidu.com;
    }


}

First, clear the browser cache, visit http://www.b.com:8084/abc.html
Insert picture description here
and modify the return URL

server {
    
    
    listen        8084;
    root          /data/nginx/domain5;
    server_name   www.b.com;
    location      /   {
    
    
        root          /data/nginx/domain5;
        autoindex     on;
    }
    location      /abc.html   {
    
    
        return    http://www.nginx.org;
    }


}

Visit
http://www.b.com:8084/abc.html directly to redirect to the new configuration.
Insert picture description here
301 configuration is as follows

server {
    
    
    listen        8084;
    root          /data/nginx/domain5;
    server_name   www.b.com;
    location      /   {
    
    
        root          /data/nginx/domain5;
        autoindex     on;
    }
    location      /abc.html   {
    
    
        return  301  http://www.nginx.org;
    }


}

Visit http://www.b.com:8084/abc.html At this time, the page is redirected to nginx.org,
Insert picture description herebut after we modify the return URL; when the browser cache is not cleared, the redirection is still
configured for nginx.org as follows

server {
    
    
    listen        8084;
    root          /data/nginx/domain5;
    server_name   www.b.com;
    location      /   {
    
    
        root          /data/nginx/domain5;
        autoindex     on;
    }
    location      /abc.html   {
    
    
        return  301  http://www.baidu.com;
    }


}

Visit http://www.b.com:8084/abc.html. At this time, the page is still redirected to nginx.org.
Insert picture description here
After we clear the browser cache, we will be redirected to www.baidu.com. The
Insert picture description here
above is a 301 redirect. The redirected information is cached locally. When the cache exists, the redirected address will be obtained from the cache. If there is no cache, it will go back to the server to obtain the redirected address.

Guess you like

Origin blog.csdn.net/weixin_45937255/article/details/115345297