The domain1.com.conf
looks correct. I presume it looks correct to you too, so I guess we’re both surprised by the redirect from www.domain1.com to sub.domain2.com. The second server
block should match the the www.domain1.com request and return 301
to domain1.com
.
Were there any failures during initial provisioning?
Could you SSH in to the server and…
- check the nginx config by running
sudo nginx -t
- reload nginx by running
sudo service nginx reload
- then test the redirect again, maybe even in a different browser (Chrome caches redirects)
I’m not familiar enough with the possibilities to catalogue them, but are there any other services involved that could be responsible for the redirect (DNS settings, caching proxies, etc.)?
Edit: Maybe turn rewrite_log on
and check your logs