0

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!

Melody
  • 23
  • 3
  • @RichardSmith not I get "redirecting too many times" :( – Melody May 21 '22 at 07:41
  • Use `curl -I` to test your server. What URL is being redirected to `domain.com`? Is it http or https. Edit your question and add the output of `curl -I` and any relevant entries in the access and error logs. – Richard Smith May 21 '22 at 08:17
  • It is fairly common for web applications to be configured with a base URL and the redirect may be happening at the application level rather than in your web server configuration. (I don't see anything obvious there) Note that permanent redirects (301) are cached by your bowser and any changes won't be picked up when you test from your desktop webbrowser. - For more about testing/debugging https://serverfault.com/q/1092950/960939 – Rob May 21 '22 at 14:16

0 Answers0