I want to serve the right ssl certificate based on the $host variable with an exception for any host being *.mydomain.com or mydomain.com
The certificates fall in two groups:
- Local certificates: *.mydomain.com mydomain.com
- External certificates: www.user1.com www.user2.com
It is important to know that www.user1.com and www.user2.com are set with CNAME to point to user1.mydomain.com and user2.mydomain.com, meaning they are being caught by the same server section that handles *.mydomain.com but the value of $host stays www.user1.com or www.user2.com. That means I've got to deal with this in one server {} block.
Based on that I want to have an if-statement that checks whether the $host variable is a subdomain of *.mydomain.com or mydomain.com and load my certificate. If not, I want to check whether the certificate of a user exists in /etc/$host/certificate and load that.
I'm vaguely familiar with nginx and I've read of the dislike of if-statements and now I'm wondering what the best way would be to get this done. I've got a lot done and this last step is just what's left.