Learn about Centmin Mod LEMP Stack today
Become a Member

SSL Has anyone setup an SSL Redirect Farm?

Discussion in 'Domains, DNS, Email & SSL Certificates' started by BamaStangGuy, Jan 8, 2019.

  1. BamaStangGuy

    BamaStangGuy Active Member

    538
    165
    43
    May 25, 2014
    Ratings:
    +218
    Local Time:
    3:09 AM
    I have a new project that I am working on where I will end up having a massive amount of domain names that I wish to redirect to one domain name.

    This used to be easy before SSL became as popular as it is now. Now, some of these domains are going to have https urls instead of http ones and they will not redirect properly by simply using your domain registrars redirect feature.

    What options do I have here? I am looking for something that would be quick and not break the bank. Nothing else will be on this server other than purely domain name redirects using SSL certificates.
     
  2. eva2000

    eva2000 Administrator Staff Member

    37,710
    8,254
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +12,710
    Local Time:
    7:09 PM
    Nginx 1.15.x
    MariaDB 5.5/10.x
    You could bulk add all domains to Cloudflare via Cloudflare API for DNS and proxy/CDN management and then use Cloudflare API to setup page rule redirects for How do I perform URL forwarding or redirects with Cloudflare? just need to use Cloudflare API to bulk on mass setup the pagerule.

    What problems you having now ?

    You mean for instance you have domain.net and domain2.net and domain3.net and domain4.net all redirecting to domain.com with
    • non-https domain.net redirect to https domain.com
    • https domain2.net redirect to https domain.com
    • non-https domain3.net redirect to https domain.com
    • https domain4.net redirect to https domain.com
    Below all assume domain.com https target destination is already setup and working

    redirect non-https domains listed in server_name directive to domain.com https site
    Code (Text):
    # for non-https domains all listed in server_name directive
    # if unsure use return 302 temp before using return 301 permanent
    server {
      listen 80;
      server_name domain.net www.domain.net domain2.net www.domain2.net domain3.net www.domain3.net domain4.net www.domain4.net;
      return 302 https://domain.com$request_uri;
    }
    

    redirect domain2.net https site to domain.com https site provided domain.net is already running Centmin Mod with letsencrypt SSL/https setup
    Code (Text):
    # each https domain i.e. domain2.net needs it's own letsncrypt
    # ssl certificate and redirect via 302 temp first than later 301 permanent
    server {
      listen 443 ssl http2;
      server_name domain2.net www.domain2.net;
    
      ssl_dhparam /usr/local/nginx/conf/ssl/domain2.net/dhparam.pem;
      ssl_certificate      /usr/local/nginx/conf/ssl/domain2.net/domain2.net.crt;
      ssl_certificate_key  /usr/local/nginx/conf/ssl/domain2.net/domain2.net.key;
      include /usr/local/nginx/conf/ssl_include.conf;
    
      return 302 https://domain.com$request_uri;
    }
    

    redirect domain4.net https site to domain.com https site provided domain.net is already running Centmin Mod with letsencrypt SSL/https setup
    Code (Text):
    # each https domain i.e. domain4.net needs it's own letsncrypt
    # ssl certificate and redirect via 302 temp first than later 301 permanent
    server {
      listen 443 ssl http2;
      server_name domain4.net www.domain4.net;
    
      ssl_dhparam /usr/local/nginx/conf/ssl/domain4.net/dhparam.pem;
      ssl_certificate      /usr/local/nginx/conf/ssl/domain4.net/domain4.net.crt;
      ssl_certificate_key  /usr/local/nginx/conf/ssl/domain4.net/domain4.net.key;
      include /usr/local/nginx/conf/ssl_include.conf;
    
      return 302 https://domain.com$request_uri;
    }
    

    FYI, you can bulk add Centmin Mod Nginx vhosts via tips and nv command line outlined at [Guide] Save time creating Nginx vhost & MySQL users and databases too with or without Letsencrypt SSL cert and HTTP/2 HTTPS.

    It's fairly easy to just write a script if you know how to automate generation of above Nginx vhost configs for non-https to domain.com and https to domain.com redirects combined with nv command line bulk creation of domains on a single server if they currently don't have a home/server. Of course more tricky if the domains are already existing sites on their own servers, in which case you'd have to modify them on server level if not via Cloudflare method I outlined early at DNS and Cloudflare API level.
     
..