I'm serving a webservice (API + Webiste) through nginx and its canonical domain name changed recently. The API is split from the user-facing website by subdirectories (eg /api/ and /download/ are part of the API, the rest belongs to the website).
I'd now like to redirect the website-part to the new domainname but serve the API requests without redirects (to keep server load down).
Because the webserver can be accessed through a number of domains, I'd need to redirect everything that doesn't match the new canonical one; something like
IF request-domain != new-domain
AND resource not in (/api/, /download/):
redirect to new domain
ELSE:
# serve site
proxy_pass http://app_server;
I didn't find a way suitable way in nginx to do the (double) negative comparison, and I can't invert them to a positive comparison, because both alternative domain names and non-API resources are quite a lot that I don't want to maintain in the nginx config.
Any ideas would be highly appreciated!