No nginx, você geralmente não quer usar se para alterar o comportamento com base no cabeçalho do host ou no uri. Você precisa de um segundo servidor:
server {
# Make sure this listen matches the one in the second server (minus default flag)
listen 80;
server_name new-domain;
# All your normal processing. Is it just proxy_pass?
location / {
proxy_pass http://app_server;
}
}
server {
# If you listen on a specific ip, make sure you put it in the listen here
# default means it'll catch anything that doesn't match a defined server name
listen 80 default;
server_name old-domain; # and everything else, but it's good to define something
# Everything that doesn't match /api/ or /download/
location / {
rewrite ^ http://new-domain$request_uri? permanent;
}
# You may want some common proxy_set_header lines here in the server
# if you need them
location /api/ {
proxy_pass http://app_server;
}
location /download/ {
proxy_pass http://app_server;
}
}