0

Basically, I am trying to use the proxy_pass directive to call a remote API.

So far, this is what I got:

server {
  location /a {
    proxy_pass https://a.com;
    rewrite ^/a(.*)$ $1 break; # no trailing slash, defined in application code
  }
  location /b {
    proxy_pass https://b.com;
    rewrite ^/b(.*)$ $1 break; # no trailing slash, defined in application code
  }
  location / {
    # Rest of configuration
  }
}

I am stuck with the fact that location /a works fine but location /b doesn't for some reason (HTTP/404).


I tried using a trailing slash for location /b this way

location /b/ {
  proxy_pass https://b.com/;
  rewrite ^/b/(.*)$ $1 break;
}

but this doesn't work either.

Any help is very welcome.

Askirkela
  • 131
  • 5

1 Answers1

0

I found the answer to my particular issue.

The two API servers are not configured the same way and I had to tweek the nginx config a bit.

  • Server b.com needed a proxy_set_header Host $host directive and no rewrite directive
  • Server a.com needed the rewrite directive but not the proxy_set_header Host $host

This leaves me with the following (working for me) config:

server {
    location /a {
        proxy_pass  https://a.com;
        rewrite ^/a(.*)$ $1 break;
    }
    location /b {
        proxy_set_header Host $host;
        proxy_pass  https://b.com;
    }
}
Askirkela
  • 131
  • 5