0

I'm having trouble redirecting *.domain1.com on one server to *.domain2.com on another server as part of a migration process. Can someone clue me into how to set up the proxy_pass to do this? The following doesn't seem to work:

    server {
        listen 80;
        server_name ~^(?<subdomain>.+)\.domain1\.com$;

        location / {
            proxy_pass http://$subdomain.domain2.com;
        }
    }

In the logs I get: *1 no resolver defined to resolve subdomain.domain2.com, client: 72.***.***.*9, server: ~^(?<subdomain>.+)\.domain1\.com$, request: "GET /index HTTP/1.1", host: "subdomain.domain1.com"

Any help would be appreciated!

0

You need to add a resolver directive in your location part.
If you have your own DNS server you can make it point to it, otherwise maybe 8.8.8.8 (Google one).
For more info, the official doc.

server {
    listen 80;
    server_name ~^(?<subdomain>.+)\.domain1\.com$;

    location / {
        resolver ip.of.your.resolver;
        proxy_pass http://$subdomain.domain2.com;
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.