2

I want to proxy requests like these: http://myproxy.com/api/folder1/result1?test=1
, http://myproxy.com/api/folder3447/something?var=one

to the equivalent destinations: http://destination.com/folder1/result1?test=1 and http://destination.com/folder3447/something?var=one, practically only the domain changes and all subfolders and params are preserved

location in config looks like:

location ~* ^/api/(.*) {
    proxy_pass http://destination.com/$1$is_args$args;
    proxy_redirect off;
    proxy_http_version 1.1;
    proxy_set_header Connection "";
    proxy_set_header  X-Real-IP  $remote_addr;
    proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
    #proxy_set_header  Host $http_host;
  }

1 Answer 1

6

You should be able to simplify your configuration slightly:

location /api/ {
    // Note the slash at end, which with the above location block
    // will replace "/api/" with "/". This will not work with regex
    // locations
    proxy_pass http://destination.com/;
    proxy_redirect off;
    proxy_http_version 1.1;
    proxy_set_header Connection "";
    proxy_set_header  X-Real-IP  $remote_addr;
    proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.