灰儿 发表于 2022-9-22 14:46:20

nginx中的proxy_redirect的使用

一 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_namewww.test.com;
    location / {
      rewrite /(.*) https://www.test.com/$1 break;
    }
}
页: [1]
查看完整版本: nginx中的proxy_redirect的使用