找回密码
 注册
首页 ≡≡网络技术≡≡ 服务器 nginx中的proxy_redirect的使用

linux nginx中的proxy_redirect的使用

灰儿 2022-9-22 14:46:20
一 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这个指令可以为被代理服务器发出的相对重定向增加主机名:


灰儿 楼主 2022-9-22 14:49:49
#访问域名http://www.test.com/zabbix
server {
    listen       80;
    server_name  www.test.com;
    location / {
        rewrite /(.*) https://www.test.com/$1 break;
    }
}
您需要登录后才可以回帖 登录 | 注册
学习中心
站长自定义文字内容,利用碎片时间,随时随地获取优质内容。
Q设计语言 了解更多
Q Design 提供商家设计所需的指导与资源,帮商家快速完成产品设计、降低生产成本。
学习中心
站长自定义文字内容,利用碎片时间,随时随地获取优质内容。
Q设计语言 了解更多
Q Design 提供商家设计所需的指导与资源,帮商家快速完成产品设计、降低生产成本。