Multiple domain with SSL - Proxy Pass

Assume I have 100 domains. a1.com a2.com a3.com
I want to proxy pass these domains to mydomain.com/a1 mydomain.com/a2 mydomain.com/a3

I tried the following

server{
server_name ${host}
listen 443;
ssl_certificate /etc/letsencrypt/live/${host}/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/${host}/privkey.pem;
include /etc/letsencrypt/live/options-ssl-nginx.conf;
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;

location / {
proxy_pass www.mydomain.com/${host};
    }
}

Please suggest if this implementation is correct?

Hi @elg, and welcome to the LE community forum :slight_smile:

Although this question is unrelated to the purpose of this forum, I will point out one thing (and provide you with a working example).

Based on your example:
${host} would assume the values [a1.com, a2.com, a3.com, ...]
Using proxy_pass www.mydomain.com/${host};
The resulting path should be like: www.mydomain.com/a1.com
Your request was for it to be like: mydomain.com/a1

The "www" is easily added or removed.
The ".com" is not as easy to remove; but it can be removed with a bit more cleverness:
Try:

server_name ~^(?<subdomain>\w+)\.com$;
proxy_pass mydomain.com/$subdomain;

Feel free to send me a :beer:

2 Likes

Thank you for helping out.
I am now using virtual hosts.

1 Like