Question

Excluding subdomains with nginx and 301 redirect to https?

I recently moved a website from Dreamhost to an Ubuntu LEMP droplet. Much, much faster. This also allowed us to enable HTTPS using our preexisting wildcard certficate. I’ve setup a redirect to move all incoming traffic on http://[www.]domain.tld:80 to https://[www.]domain.tld:443 like so:

server {
       listen         80;
       server_name    domain.tld www.domain.tld;
       return         301 https://domain.tld$request_uri;
}

This works really well. Too well! I still have a few subdomains hosted at Dreamhost, which are HTTP only. Now any browser that first visits domain.tld always prefixes https:// instead of http://. I understand this working on the explicit www.domain.tld and domain.tld, but why is this 301 redirect being applied by browsers to all subdomains? Is there anyway to do this differently so that unspecified subdomains are not included in the 301?

Show comments

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

This question was answered by @sleepdreaming:

How are your subdomains configured in your DNS? If they are CNAMES then there will be a conflict since you moved your main domain.tld to another server (and another IP of course). If they ARE CNAMES then you need to change them to A records with the IP address of your previous server so they will resolve to that IP instead of your DO droplet.

View the original comment