3

i want to do proxy_pass

from https://foo.bar/api/v1/users/{userId}/store/{storeCode}/status to https://bar.foo/api/v1/users/{userId}/store/{storeCode}/status

and also

from https://foo.bar/api/v1/users/{userId}/opendate to https://bar.foo/api/v1/users/{userId}/opendate

the different with that 2 links are http method that use to access, later we will limit access with limit_except, but now i want to proxy_pass the request first.

i've made a configuration like this

location /api/v1/users/[0-9a-z]+/store {
    proxy_pass https://bar.foo/api/v1/users/[0-9a-z]+/store;
    proxy_set_header Host $proxy_host;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For proxy_add_x_forwarded_for;
    proxy_redirect off;
    proxy_buffering off;
    proxy_ssl_protocols TLSv1.2;
    proxy_ssl_server_name on;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_pass_request_headers on;
}


location /api/v1/users/[0-9a-z]+/opendate {
    proxy_pass https://bar.foo/api/v1/users/[0-9a-z]+/opendate;
    proxy_set_header Host $proxy_host;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For 
    proxy_add_x_forwarded_for;
    proxy_redirect off;
    proxy_buffering off;
    proxy_ssl_protocols TLSv1.2;
    proxy_ssl_server_name on;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_pass_request_headers on;
}

but i still don't get my server proxying the request. is there anyone know how to proxy_pass long directive location with some regex in nginx ?

1 Answer 1

0

If that is a regular expression, you are using the wrong syntax for the location directive. See this document for details.

You only need to give proxy_pass a URI part, if the URI is changed before passing upstream. See this document for details.

For example:

location ~ ^/api/v1/users/[0-9a-z]+/store {
    proxy_pass https://bar.foo;
    ...
}
1
  • its work for me. thank you so much
    – jack deace
    Oct 16, 2019 at 9:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .