Хочу генерировать конфиг таким образом:
server {
include /etc/nginx/http.conf;
server_name domain1;
return 301 https://$host$request_uri;
}
server {
server_name domain1;
include /etc/nginx/https.conf;
ssl_certificate /etc/letsencrypt/live/domain1/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/domain1/privkey.pem;
auth_basic "Unauthorized";
auth_basic_user_file /etc/nginx/.htpasswd;
location / {
proxy_pass http://dd1;
}
}
server {
include /etc/nginx/http.conf;
server_name domain;
return 301 https://$host$request_uri;
}
server {
server_name domain2;
include /etc/nginx/https.conf;
ssl_certificate /etc/letsencrypt/live/domain2/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/domain2/privkey.pem;
auth_basic "Unauthorized";
auth_basic_user_file /etc/nginx/.htpasswd;
location / {
proxy_pass http://dd2;
}
}
Например(нерабочее):
#!/usr/bin/php-example
<?php
ob_start();
var domains = [
"domain1": "dd1",
"domain2": "dd2"
];
foreach(domains as domain=>proxyHost) {
server {
include /etc/nginx/http.conf;
server_name $domain;
return 301 https://$host$request_uri;
}
server {
server_name $domain;
include /etc/nginx/https.conf;
ssl_certificate /etc/letsencrypt/live/$domain/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/$domain/privkey.pem;
auth_basic "Unauthorized";
auth_basic_user_file /etc/nginx/.htpasswd;
location / {
proxy_pass http://$proxyHost;
}
}
}
Сложность еще что ssl_certificate не поддерживает переменные
Вижу варианты генерировать bash/php/python
Есть нативные или элегантные способы?