例如,访问test.com,在nginx上转发到127.0.0.1:8080的项目,但现在需要在项目中从代码中获取test.com
在nginx配置中添加以下配置即可。
proxy_redirect off; proxy_set_header Host $http_host; proxy _ set _ headerx-real-IP $ remote _ addr; proxy _ set _ headerx-forwarded-for $ proxy _ add _ x _ forwarded _ for; 说明proxy_redirect
语法: proxy _ redirect [默认]
默认值: proxy_redirect default
使用字段: http、服务器、位置
如果需要更改代理服务器发送的响应标头中的" Location "和" Refresh "字段,可以使用此命令进行设置。
代理服务器在位置字段中输入http://localhost :8000/two/some/uri /
此命令:
将proxy _ redirect 3358 localhost :8000/two/http://frontend/one/location字段改写为http://frontend/one/some/uri/您可以不在替代字段中写入服务器名称。
proxy _ redirect 3358 localhost :8000/two//; 这将使用服务的基本名称和端口,即使它们来自80个以外的端口。
使用default参数时,它是根据location和proxy_pass参数的设置确定的。
例如,以下两种配置是等效的:
位置/one/{ proxy _ pass http://upstream :端口/two/proxy _ redirect default; } location/one/{ proxy _ pass http://upstream :端口/two/proxy _ redirect http://upstream :端口/two//one/}命令
proxy _ redirect 3358 localhost :8000/http://$ host : $ server _ port /
这个命令可以偶尔重复。
proxy_redirect default; proxy _ redirect 3358 localhost :8000//; proxy_redirect; //; 参数off在此字段中禁止所有proxy_redirect指令。
proxy_redirect off;
使用此命令,可以增加来自代理服务器的相对重定向的主机名。