Error in multiple domains with nginx when add certboot certificate

Viewed 405

I have an Ubuntu 20.04 server on Azure, with Nginx, PHP-FPM and actualy two websites. The sites are example.com and sub.example.com and They are with the certificate issued by certboot and working fine. I added a third site with a diferente domain example2.com and it worked fine. But when I add certboot to this third site, they all stop working, and Nginx don’t stop and don't show any error. I added the certificates using this

sudo certbot --nginx -d example.com -d www.example.com sudo certbot --nginx -d sub.example.com Until here ok, sites working fine last five months

Then I add a new website and worked fine two, but when a I add certbot, all of them stop to work, but nginx still running withou erros sudo certbot --nginx -d example2.com -d www.example2.com

sudo nginx -t nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful

Sites only work again if I remove the certificate from the third site

sudo sudo certbot delete --cert-name example2.com

sorry for my english

Server block Site 1

server {
        root /var/www/example.com/html;
        index index.php index.html index.htm index.nginx-debian.html;
        server_name example.com www.example.com;
        location / {
                try_files $uri $uri/ /index.php?$args;
        }
        location ~ \.php$ {
                try_files $uri =404;
                fastcgi_pass unix:/run/php/php7.4-fpm.sock;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include fastcgi_params;
  }

    listen [::]:443 ssl ipv6only=on; # managed by Certbot
    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/example.com/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.example.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


    if ($host = example.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot
        listen 80 default_server;
        listen [::]:80 default_server;
        server_name example.com www.example.com;
    return 404; # managed by Certbot
}

Server block Site 2 (subdomain site 1)

server {
        root /var/www/sub.example.com/html;
        index index.php index.html index.htm index.nginx-debian.html;
        server_name sub.example.com;
        location / {
                try_files $uri $uri/ /index.php?$args;
        }
        location ~ \.php$ {
                try_files $uri =404;
                fastcgi_pass unix:/run/php/php7.4-fpm.sock;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include fastcgi_params;
        }
    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/sub.example.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/sub.example.com/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 = sub.example.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot
        listen 80;
        server_name sub.example.com;
return 404; # managed by Certbot
}

Server block Site 3

server {
        root /var/www/example2.com/html;
        index index.php index.html index.htm index.nginx-debian.html;
        server_name example2.com www.example2.com;
        location / {
                try_files $uri $uri/ =404;
        }
        location ~ \.php$ {
                try_files $uri =404;
                fastcgi_pass unix:/run/php/php7.4-fpm.sock;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include fastcgi_params;
  }
    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/example2.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/example2.com/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.example2.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


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

        listen 80;

        server_name example2.com www.example2.com
    return 404; # managed by Certbot

}

0 Answers
Related