23

I have one NGINX acting as reverse proxy. I need to remove a substring string_1 from the URL, the rest of the URL is variable.

Example:

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;

Thanks,

@pcamacho

Pedro
  • 707

2 Answers2

24

It's really basic and simple. Just add /path/ part to proxy_pass and nginx will replace locations prefix with that path. You need to replace /string_1/ with /, so do it:

location /string_1/ {
    proxy_pass  http://internal_host:port/;
}
Alexey Ten
  • 9,247
17

I found the way to rewrite the proxy_pass URL:

  location  /string_1/   {  

    if ($request_uri ~* "/string_1/(.*)") { 
            proxy_pass  http://internal_host:port/$1;
    }   

  }

Regards,

@pcamacho

Pedro
  • 707