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
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.
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,
but 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.
After we clear the browser cache, we will be redirected to www.baidu.com. The
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.