我有一个NGINX作为反向代理。 我需要从URL中删除子串string_1,其余的URL是可变的。
例:
Origin: http://host:port/string_1/string_X/command?xxxxx Destination: http://internal_host:port/string_X/command?xxxxx
nginx.conf:
location /string_1/ { proxy_pass http://internal_host:port/$request_uri$query_string;
谢谢,
@pcamacho
我find了重写proxy_pass URL的方法:
location /string_1/ { if ($request_uri ~* "/string_1/(.*)") { proxy_pass http://internal_host:port/$1; } }
问候,
@pcamacho
这真的很简单 只需将/path/ part添加到proxy_pass ,nginx将用该pathreplacelocation的前缀。 你需要用/string_1/replace/string_1/ / ,那么就这样做:
location /string_1/ { proxy_pass http://internal_host:port/; }