1

I had a proxy server which redirects communications to some api on customer side via https. When I use configuration with set upstream variable (proxy_pass $upstream_endpoint$request_uri;), the DNS resolving for this domain (dynamic changing IP adress) is working well but I get response 403 unauthorized.

When I use configuration without upstream (proxy_pass https://api-test.example.com/api/), point directly to customer domain it works well, I am getting response 200 but DNS resolver is not working anymore..

Nginx config:

location /api-test.example.com/api/ {
            resolver 10.100.10.1 valid=5s;
            set $upstream_endpoint https://api-test.example.com;
            proxy_pass $upstream_endpoint$request_uri;
            #proxy_pass https://api-test.example.com/api/;
            proxy_ssl_name api-test.example.com;
            proxy_ssl_server_name on;
            proxy_set_header Host api-test.example.com;
            proxy_set_header X-Forwarded-Proto https;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
4
  • $request_uri is not the same as /api/ - are you missing a rewrite? Commented Oct 11, 2018 at 8:27
  • Hi Richard Yes $request_uri is the same as /api/ Do you mean it should be as set $upstream_endpoint api-test.domain.com/api; proxy_pass $upstream_endpoint; Commented Oct 11, 2018 at 8:40
  • No, I mean that the value of $request_uri is equal to /api-test.domain.com/api/ and not /api/. Commented Oct 11, 2018 at 8:42
  • its possible issue. How should i fixed it? just remove from proxy_pass $upstream_endpoint$request_uri; Final should be: proxy_pass $upstream_endpoint; ?? Commented Oct 11, 2018 at 8:46

1 Answer 1

0

By adding a URI to the proxy_pass statement, the requested URI is rewritten before passing it upstream. See this docuement for details.

So the URI /api-test.example.com/api/foo is rewritten to /api/foo.

You can achieve the same behaviour with a rewrite...break statement. See this document for details.

location /api-test.example.com/api/ {
    rewrite ^/api-test.example.com(.*)$ $1 break;
    set $upstream_endpoint https://api-test.example.com;
    proxy_pass $upstream_endpoint;
    ...
}
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.