0

I have a NGINX configuration with two virtual hosts (server {} blocks): one serving a human-readable site on the primary domain, and the other acting as a reverse-proxy for a specialized service on a subdomain.

http {
    <...>

    server {
        listen 443 ssl http2;
        server my.tld;
        <...>

        location / {
            root /srv/http;
            <...>
        }
    }

    server {
        listen 443 ssl http2;
        server svc.my.tld;

        <complex reverse-proxy setup with many location blocks>
    }
}

For some reason, some clients of the specialized service send their requests to the primary domain (i. e. I see my.tld/api/endpoint instead of svc.my.tld/api/endpoint in the logs). I cannot fix these clients. They also don't follow redirects.

Is there any way to transparently redirect those requests into the correct server {} block, without duplicating the whole reverse-proxy configuration in the main server block?

intelfx
  • 134
  • 7
  • If it's that clear `/api/endpoint` is the pattern for those clients, then you can add a `location` block in the `my.tld` `server` block to reverse proxy such requests to `svc.my.tld` (and as you wished, not to clone things from within `svc.my.tld` `server` block). – Lex Li Dec 17 '22 at 19:15
  • You can use `include` directive to avoid code duplication. – AlexD Dec 19 '22 at 07:10

0 Answers0