Warm tip: This article is reproduced from serverfault.com, please click

Install SSL certificates and Virtual Hosts for new domains through API

发布于 2020-10-07 17:29:50

I'm trying to create a web app which works kind of like a website 'generator'. It is based upon Wordpress Multisite and an API that communicates with Wordpress.

Wordpress is installed on a Digital Ocean Apache server. The Wordpress API integration works and I can create new sites on Wordpress from my web app.

The problem is when I try to integrate domains into the whole thing. As of now new sites gets created as subdomains, f.eg. newsite.primarydomain.com . Now I want to allow my users to buy and use a custom domain, and my idea was to use the Namecheap API. However, I cannot for the life of me grasp how I should get this to work with SSL and at the same time have userscustomdomain.com as a mock for newsite.primarydomain.com .

I have working Let's Encrypt-certificates for primarydomain.com and *.primarydomain.com . And I tried using both A, CNAME and ALIAS records which pointed the custom domain correctly, but I got a insecure https warning because the SSL-certificate was issued for primarydomain.com and not userscustomdomain.com .

I actually got it to work when I did things manually, and installed a new SSL-certificate with certbot through my apache terminal. That installed the certificate and automatically added an apache Virtual Host record. But how do I get all this to work automatically from my web app? In other words, do I need to create vHost-records and install SSL from an API or similar? I'm open to pretty much any solution, small, large, free, paid.

It seems this is a pretty niche problem and would really really apprieciate any pointer in the right direction! :)

Questioner
Rasmus Lian
Viewed
11
21k 2020-11-29 04:19:10

I ended up ditching Apache and using Caddy Server instead. It has awesome API support and automatic Let's Encrypt-certificates. Would highly recommend.