【发布时间】:2017-08-12 18:48:36
【问题描述】:
我将 nginx 配置为反向代理。
我需要更改(重写?)URL,例如:当请求(到 nginx 反向代理)是“http://example.com/test/?username=test1;password=passwdtest1”时,它必须“修改”到主服务器为“http://example.com/test/?username=production;password=passwdproduction1”。
考虑到在原始请求中,“username=test1;password=passwdtest1”字段并不总是相同的(它们会发生变化),相反,主服务器的“修改”字段总是相同的。
其他更清楚的例子:
"/test/?username=test1;password=passwdtest1" -> "/test/?username=production;password=passwdproduction1"
"/test/?username=test1876;password=somepasswd" -> "/test/?username=production;password=passwdproduction1"
"/test/?username=somevalues;password=somepasswdvalue" -> "/test/?username=production;password=passwdproduction1"
因此,与“?username=somevalues;password=somepasswdvalue”的值无关,它应该始终变为“?username=production;password=passwdproduction1”。
感谢您的帮助!
【问题讨论】:
-
更新:我是这样解决的:
location ~ /test/ { if ($args ~ "username=(.+);password=(.+)") { rewrite ^.*$ "/test/?username=production;password=passwdproduction1" break; }
标签: nginx url-rewriting reverse-proxy remap