我需要代理到不同的后端但使用相同的 URL,因此重写应该是这样的
URL: http://myservrer.com/server/monitoring1?(parameters)
REWRITE TO: http://1.1.1.1/server/monitoring?(parameters)
URL: http://myservrer.com/server/monitoring2?(parameters)
REWRITE TO: http://2.2.2.2/server/monitoring?(parameters)
我当前的配置:
location /server/monitoring1 {
proxy_pass http://1.1.1.1:82/server/monitoring;
}
location /server/monitoring2 {
proxy_pass http://2.2.2.2:82/server/monitoring;
}
如何使用重写选项来改变它?
答案1
location /server/monitoring1 {
rewrite ^/server/monitoring1\?(.*) http://1.1.1.1:82/server/monitoring?$1 redirect;
}
location /server/monitoring2 {
rewrite ^/server/monitoring2\?(.*) http://2.2.2.2:82/server/monitoring?$1 redirect;
}