How to Preserve Request Url With Nginx Proxy_Pass

How to preserve request url with nginx proxy_pass

I think the proxy_set_header directive could help:

location / {
proxy_pass http://my_app_upstream;
proxy_set_header Host $host;
# ...
}

How to preserve request url with nginx proxy_pass on Mac OSX

If you don't want the URL to change (e.g., due to Nginx pass_proxy subdirectory without url decoding), you should omit the trailing slash from your proxy_pass:

-proxy_pass   http://my_app_upstream/;
+proxy_pass http://my_app_upstream;

NGINX proxy pass a portion of the request URL

This is really simple:

location /path1/ {
proxy_pass http://localhost:8000/;
proxy_http_version 1.1;
}

Read this Q/A for details.

Update

This solution isn't usable after OP clarifies his question.

If all of the additional paths share common suffix path2:

location /path1/path2 {
rewrite ^/path1(.*) $1 break; # remove '/path1' URI prefix
proxy_pass http://localhost:8000;
proxy_http_version 1.1;
}

If they aren't, replace location /path1/path2 with location ~ ^/path1/(?:path2a|path2b|path2c).

If you need to pass to the backend query arguments that are different from those came with the request, use

set $args query1=some-query;

within the location block.

Nginx reverse proxy destination from request url

Solution:

This is the solution I've found:

location  ~ "/go/([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})(.+)$" {
proxy_pass http://$1:80$2;
sub_filter "" "";
sub_filter_once off;
sub_filter_types application/json application/x-javascript;
sub_filter '"/flash/' '"/go/$1/flash/';
sub_filter '"/rom/' '"/go/$1/rom/';
}

For example I can use the following url: http://myproxyserver/go/192.168.0.100/
and I get the response from the 192.168.0.100 throw the nginx reverse proxy.



Related Topics



Leave a reply



Submit