Report this

What is the reason for this report?

Nginx, SSL, multiple domains

Posted on July 6, 2015

Hi folks!

Have been straggling around nginx.conf for multiple domains.

This is what I have

  1. 3 domains
  2. SSL cert
  3. Droplet
  4. nginx

I want to redirect all https, https://www, http, http://www to one of the domain from these 3. Simply saying, all should go to just https://www.example.com

ssl_certificate /var/www/domain1.com/shared/ssl/bundle.crt; 
ssl_certificate_key /var/www/domain1.com/shared/ssl/www_domain1_com.key;
ssl_verify_depth 3;

server {
	listen         *:80;
	server_name    www.domain1.com domain1.com www.domain2.com domain2.com www.domain3.com domain3.com;
	return         301 https://www.domain1.com$request_uri;
}

server {
	listen         *:443 ssl;
	server_name   domain1.com www.domain2.com domain2.com www.domain3.com domain3.com;
	return         301 https://www.domain1.com$request_uri;
}


server {
    	server_name www.domain1.com;
    	listen 443 ssl;
    	root /var/www/domain1.com/current/public;
    	access_log /var/www/domain1.com/current/log/nginx.access.log;
    	error_log /var/www/domain1.com/current/log/nginx.error.log info;
}

these above config does not have any configuration issues. nginx -t give “ok”.

But the problem is that all https requests (which are not from domain1.com) trying to shake ssl hands which is not true. they should 301-ing to www.domain1.com

I have tried doing some playing around in default config, seemed do not help!

any suggestions - would be great!

The developer cloud

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

Start building today

From GPU-powered inference and Kubernetes to managed databases and storage, get everything you need to build, scale, and deploy intelligent applications.