一 proxy_redirect的作用
proxy_redirect 该指令用来修改被代理服务器返回的响应头中的Location头域和“refresh”头域。
二 语法结构
1 2 3 | 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.在代替的字段中可以不写服务器名:
1 | proxy_redirect http://localhost:8000/two/ /; |
这样就使用服务器的基本名称和端口,即使它来自非80端口。
3.参数off将在这个字段中禁止所有的proxy_redirect指令:
1 2 3 | proxy_redirect off; proxy_redirect default; proxy_redirect http://localhost:8000/ /; proxy_redirect ; /;1. |
4.利用proxy_redirect这个指令可以为被代理服务器发出的相对重定向增加主机名:
扩展:nginx proxy_redirect https配置后端http302跳转处理
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | # 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; location /mgr/ { proxy_pass http://localhost:8080/mgr/; } } |
到此这篇关于nginx中的proxy_redirect的使用的文章就介绍到这了,更多相关nginx proxy_redirect的使用内容请搜索IT俱乐部以前的文章或继续浏览下面的相关文章希望大家以后多多支持IT俱乐部!