0

here my conf file

    server {
        root /var/www/[NAME]/latest;
        index index.php index.html index.htm index.nginx-debian.html;
        server_name [SITENAME].com www.[SITENAME].com [ANOTHER-SITENAME].com www.[ANOTHER-SITENAME].com;



        location / {
                try_files $uri $uri/ =404;
        }

        location ~ \.php$ {
                include snippets/fastcgi-php.conf;
                fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
        }

        location ~ /\.ht {
                deny all;
        }


    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/[SITENAME].com-0001/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/[SITENAME].com-0001/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

}

server {
    if ($host = www.[ANOTHER-SITENAME].com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


    if ($host = [ANOTHER-SITENAME].com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


    if ($host = www.[SITENAME].com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


    if ($host = [SITENAME].com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


        listen 80;
        server_name [SITENAME].com www.[SITENAME].com [ANOTHER-SITENAME].com www.[ANOTHER-SITENAME].com;
    return 404; # managed by Certbot

}

everythign works fine when i open [SITENAME].com

but when i open [ANOTHER-SITENAME].com i get an error message

This page isn’t working [ANOTHER-SITENAME].comredirected you too many times.

why? how to fix this?

Francesco
  • 24,839
  • 29
  • 105
  • 152

1 Answers1

0
  1. Your config NEVER works for [ANOTHER-SITENAME].com, because http have redirect to https and https not working because SSL cert is only for [SITENAME].com.
  2. If have two sites who use same files, make seperate blocks for them - it will be easier to manage and troubleshoot.
  3. Make it simple, help yourself... For example:

[SITENAME].com

    server
    {
            listen 80;
            server_name www.[SITENAME].com [SITENAME].com;
            return 301 https://[SITENAME].com$request_uri;
    }
    server
    {
            listen 443 ssl;
            server_name www.[SITENAME];
            ssl_certificate /etc/letsencrypt/live/www.[SITENAME].com/fullchain.pem;
            ssl_certificate_key /etc/letsencrypt/live/www.[SITENAME].com/privkey.pem;
            return 301 https://[SITENAME].com$request_uri;
    }
    server
    {
            listen 443 ssl;
            server_name [SITENAME].com;
            root /var/www/[NAME]/latest;
            index index.php index.html index.htm index.nginx-debian.html;
            location / {
                    try_files $uri $uri/ =404;
            }
            location ~ \.php$ {
                    include snippets/fastcgi-php.conf;
                    fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
            }
            location ~ /\.ht {
                    deny all;
            }
    }

[ANOTHER-SITENAME].com

    server
    {
            listen 80;
            server_name www.[ANOTHER-SITENAME].com [ANOTHER-SITENAME].com;
            return 301 https://[ANOTHER-SITENAME].com$request_uri;
    }
    server
    {
            listen 443 ssl;
            server_name www.[ANOTHER-SITENAME].com;
            ssl_certificate /etc/letsencrypt/live/www.[ANOTHER-SITENAME].com/fullchain.pem;
            ssl_certificate_key /etc/letsencrypt/live/www.[ANOTHER-SITENAME].com/privkey.pem;
            return 301 https://[ANOTHER-SITENAME].com$request_uri;
    }
    server
    {
            listen 443 ssl;
            server_name [ANOTHER-SITENAME].com;
            root /var/www/[NAME]/latest;
            index index.php index.html index.htm index.nginx-debian.html;               
            location / {
                    try_files $uri $uri/ =404;
            }
            location ~ \.php$ {
                    include snippets/fastcgi-php.conf;
                    fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
            }
            location ~ /\.ht {
                    deny all;
            }
    }
Vykintas
  • 633
  • 5
  • 16