Problem with newly added subdomain is automatically redirect to SSL

November 5, 2016 141 views
Let's Encrypt Nginx DNS Ubuntu 16.04

Hi all,

I've already had a droplet which previously has been setup with:

  • Nginx server
  • A domain (example.com)
  • Re-route www.example.com to example.com as always.
  • Installed and config Let's Encrypt for both example.com and www.example.com
  • All HTTP will be redirected to HTTPS.

So at current state, all will be redirected to https://example.com and it is working fine.

Now, I want to add a subdomain into this droplet. I visit Networking section, add a new A record

sub.example.com. 1800 IN A 123.45.67.89

The ping works fine, it can send the packets.

When I type the address sub.example.com to web browser, I mean plain http://sub.example.com, it just automagically redirects to https://sub.example.com while I haven't set up anything for SSL.

I also tried to add a virtual host entry for sub.example.com to nginx server, it just keeps redirects to the same route https://sub.example.com.

I added access_log, error_log to nginx server config. No entry added if I visit the sub-domain.

Anyone have idea on this case? I search over Internet but haven't found any case similar to mine.

2 Answers

How does your HTTP (80) server block for example.com looks like? Make sure server_name is set only to example.com www.example.com. If there is _ or wildcard entry *.example.com make sure to change it to example.com www.example.com.
This is example how it should look like:

Sample Config
server {
    listen 80 default_server;
    listen [::]:80 default_server;
    server_name example.com www.example.com;
    return 301 https://$server_name$request_uri;
}

Setup one block that will serve some static content for sub.example.com.
You can take a look at Server blocks tutorial if it comes to help.
You can share config here so we can look at it.

When using the Nginx web server, server blocks (similar to the virtual hosts in Apache) can be used to encapsulate configuration details and host more than one domain off of a single server. In this guide, we'll discuss how to configure server blocks in Nginx on an Ubuntu...

I'm having the same issue.

1. Initial Server Setup with Ubuntu 16.04
    1. How to Use SSH Keys with DigitalOcean Droplets
    2. Community Post: Updating Ubuntu (14.04) -- Security Updates
2. How to Install Nginx on Ubuntu 16.04
3. How to Set Up Nginx Server Blocks on Ubuntu 16.04
4. How to Install Node.JS on Ubuntu 16.04

Installed in the following order above, all DigitalOcean articles. I'm stuck on #3 because my test subdomain keeps rerouting to https as well. I've combed through everything I can think of, from DNS settings to nginx.conf and sites-available/enabled and default_server.

  • I had set up two server blocks like the example (one for my domain and one for a subdomain) and I ended up just deleting the subdomain and cleared my Google Chrome cache. I followed the instructions again to make the subdomain and it worked. Sorry if that doesn't help much, but it worked for me.

Have another answer? Share your knowledge.