I have many domains like hello1.com
, hello2.com
... hello101.com
All of them having SSL Certificates by Let's encrypt.
All of this domains need to be proxied to this URI http://127.0.0.1:8000
(django
is there and it will handle everything)
So, this is Nginx
config for one domain:
server {
listen 80 default_server;
return 404;
}
server {
listen 443 ssl;
server_name hello.com;
location ~ ^/(static|media)/ {
root /hosting/hello/files;
expires 30d;
}
location / {
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Forwarded-Proto https;
proxy_pass http://127.0.0.1:8000;
proxy_set_header Accept-Encoding "";
}
ssl_certificate /etc/letsencrypt/live/hello.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/hello.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
But if I want to config all my servers, there will be a lot of repeating lines of code and it will be very difficult to maintain.
Only 3 lines of configuration are different for each domain:
server_name <domain>.com;
ssl_certificate /etc/letsencrypt/live/<domain>.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/<domain>.com/privkey.pem; # managed by Certbot
How can I move all other lines to one place? I don't want to repeat this configuration 100 times.
UPD: I can wildcard server_name
or list all domains like this:
server_name hello1.com hello2.com hello3.com etc.
Then I'll need to put current domain name (is it in $host
variable?) into this 2 strings:
ssl_certificate /etc/letsencrypt/live/<domain>/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/<domain>/privkey.pem;
How can I do it?
server_name
, otherwise I would look into scripting it.server_name
, but I also need to put domain name here:ssl_certificate /etc/letsencrypt/live/<domain>.com/fullchain.pem;
- is it possible?