0

I want to redirect / forward https://example.com second-level-domain to https://www.example.com subdomain without having a SSL certificate on registrar itself (but on own server).

My problem is, that I don't have a static ip, so can't use a A-Record / AAAA-Record, only a DynDNS Address. Also tried Alias / A-Name, but they only redirect SLD to SLD. Simple forward does not consider SSL, only simple http. I would also be satisfied, by redirecting it via own server, but SLD cannot be forwarded to my server anyway, as it has to be connected via the dynamic dns service (which has subdomain only).

(Having namecheap as registrar and DynDns)

User Rebo
  • 123
  • 6

1 Answers1

0

I found this article of FreeCodeCamp and they posted the solution.

You have to use an ALIAS record (can be combined with CNAME record).

  • ALIAS at DNSimple and namecheap
  • ANAME at DNS Made Easy
  • ANAME at easyDNS
  • CNAME (virtual) at CloudFlare

Some providers don't have any of these option (e.g. United Domains) and you may have to transfer to another provider.

Then you have to add two SSL certificates to at your Server, which looks like this in NGINX:

server {
    # Forward http://www.example.com, http://example.com to https://

    listen 80;
    listen [::]:80;
    
    server_name www.example.com example.com;

    return 301 https://$http_host$request_uri;
}

server {
    # Forward https://example.com to https://www.example.com

    listen 443 ssl;
    listen [::]:443 ssl;
    
    server_name example.com;
    
    ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; # managed by Certbot

    return 301 https://www.$host$request_uri;
}

server {
    # handle https://www.example.com

    listen 443 ssl;
    listen [::]:443 ssl;

    server_name www.example.com;
    
    ssl_certificate /etc/letsencrypt/live/www.example.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/www.example.com/privkey.pem; # managed by Certbot

    root /var/www/example.com;
    index index.html;
}
User Rebo
  • 123
  • 6