I have a small server on which I want to dynamically load ssl certs for multiple domains.
The problem is that the 2 domains that I currently have (domain.com and domain.cloud - "domain" is identical) are redirecting me to the same domain.com
. What should I change?
listen 80;
server_name domain.com domain.cloud;
access_log /var/log/nginx/root/access.log;
error_log /var/log/nginx/root/error.log warn;
# Redirect all http to https
location / {
return 301 https://$server_name$request_uri;
}
}
server {
listen 443 ssl;
server_name domain.com domain.cloud;
ssl_certificate /etc/ssl/$cert/cert.pem;
ssl_certificate_key /etc/ssl/$cert/privkey.pem;
access_log /var/log/nginx/root/access.log;
error_log /var/log/nginx/root/error.log warn;
root /var/www/root/pub;
index index.php;
location ~* \.(jpg|jpeg|gif|css|png|js|ico|html)$ {
access_log off;
expires max;
log_not_found off;
}
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
include fastcgi_params;
}
}
map $ssl_server_name $cert {
domain.com domain.com;
domain.cloud domain.cloud;
}
Thank you!