When developing on my system, I use server_name ~^(?<subdomain>.+)\.localhost$;
to capture the subdomain, however, in production, my reverse proxy is deployed over multiple domains and the domain name is stored in the nginx variable $domain
.
How do I do a regex capture while doing string interpolation at the same time.
E.g. instead of server_name ~^(?<subdomain>.+)\.localhost$
how do I do server_name ~^(?<subdomain>.+)\.${domain}$;
Actual code:
server {
listen 80;
server_name ~^(?<subdomain>.+)\.localhost$;
location / {
proxy_pass https://sarahah.com; # get the joke? ;)
proxy_set_header Host $subdomain.sarahah.com;
}