Report this

What is the reason for this report?

Nginx - SSL and Handling www / non.www domains

Posted on January 25, 2017

Hi,

I’m writing to confirm my implementation of SSL and www.mydomain.com and mydomain.com (i.e. without www) is correct.

I have certs already purchased from name.com. I’ve got those in place and referenced in the default file in the path /etc/nginx/sites-enabled and checked against sudo nginx -t to ensure syntax is ok.

This looks like:

server {
  listen 443 ssl;

  server_name www.mydomain.com mydomain.com;

  ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
  ssl_prefer_server_ciphers on;
  ssl_ciphers 'EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH';

  ssl_certificate /home/nodeapp/www.mydomain.com.chained.crt;
  ssl_certificate_key /home/nodeapp/www.mydomain.com.key;
}

I’ve added by www.mydomain.com and mydomain.com as domains, so dokku domains node app shows:

mydomain.com
www.mydomain.com

The command dokku certs:info mydomain shows the certificate details with:

=====> Common Name(s): 
=====>    www.mydomain.com
=====>    www.mydomain.com
=====>    mydomain.com

Then in my Cloudflare DNS settings (where i also have redirect from non www to www with https) I have 2 records:

A record -> mydomain.com -> points to my droplet IP CNAME record -> www -> points to @ - is an alias of mydomain.com

Advice/confirmations would be appreciated.

Many Thanks



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!

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.

@psmod2

In the directory where your server blocks are, do you happen to have an extra file that’s marked with a tilde (~) or a temp file by chance? Or even a dot, or .save, or something of that nature?

From the looks of it, NGINX is trying to load your server block twice and when it does it’s stating that the domain is already loaded from one configuration file so it’s ignoring the second.

If NGINX is setup to load everything from /etc/nginx/sites-enabled, for example, it will attempt to load everything in that directory. So if there’s an extra server block with the same information, you’ll see the logs populated with that error.

Hi,

I did a ls -a at the path /etc/nginx/sites-enabled and there is only file file default.

Anywhere else this I need to be checking?

Could this be because I have 2 domains listed - i.e. if i do dokku domains myapp, i’m presented with www.mydomain.com and mydomain.com?

@psmod2

The issue of “too many redirects” is an issue with CloudFlare. You’ll need to login to the CloudFlare control panel and under their “Crypto” tab, make sure SSL is set to “Full (Strict)” and allow that to take effect.

As for the error log, if you could, please post the full server block(s) so I can take a look at them. You can comment out the domain and/or IP’s if needed.

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.