一 proxy_redirect的作用
proxy_redirect 该指令用来修改被代理服务器返回的响应头中的location头域和“refresh”头域。
二 语法结构
proxy_redirect 旧地址 新地址; proxy_redirect default; #默认配置 proxy_redirect off; #关闭重定向
三 案例
如果需要修改从被代理服务器传来的应答头中的"location"和"refresh"字段,可以用这个指令设置。
1.假设被代理服务器返回location字段为: http://localhost:8000/two/some/uri/
这个指令:proxy_redirect http://localhost:8000/two/ http://frontend/one/;
将location字段重写为http://frontend/one/some/uri/。
2.在代替的字段中可以不写服务器名:
proxy_redirect http://localhost:8000/two/ /;
这样就使用服务器的基本名称和端口,即使它来自非80端口。
3.参数off将在这个字段中禁止所有的proxy_redirect指令:
proxy_redirect off; proxy_redirect default; proxy_redirect http://localhost:8000/ /; proxy_redirect ; /;1.
4.利用proxy_redirect这个指令可以为被代理服务器发出的相对重定向增加主机名:
扩展:nginx proxy_redirect https配置后端http302跳转处理
# https server
#
server {
listen 443 ssl;
server_name localhost;
charset utf8;
ssl_certificate full_chain.pem;
ssl_certificate_key private.key;
ssl_session_cache shared:ssl:1m;
ssl_session_timeout 5m;
ssl_ciphers high:!anull:!md5;
ssl_prefer_server_ciphers on;
proxy_set_header host $host;
proxy_set_header x-real-ip $remote_addr;
proxy_set_header x-forwarded-for $proxy_add_x_forwarded_for;
proxy_set_header x-forwarded-proto $scheme;
proxy_connect_timeout 10;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_redirect http://$host/ https://$host:$server_port/;
location /mgr/ {
proxy_pass http://localhost:8080/mgr/;
}
}到此这篇关于nginx中的proxy_redirect的使用的文章就介绍到这了,更多相关nginx proxy_redirect的使用内容请搜索代码网以前的文章或继续浏览下面的相关文章希望大家以后多多支持代码网!
发表评论