Answer the question
In order to leave comments, you need to log in
How to generate config for multiple domains?
I want to generate config like this:
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;
}
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question