'Nginx: [emerg] cannot load certificate after I deleted the certificate

I generated an SSL certificate on one of my subdomains. I then tried to delete/revoke the certificate using the command certbot delete. A little terminal menu popped up asking me what certificate I would like to delete. I deleted the one I wanted to delete. Now, when running sudo nginx -t I am getting error messages saying:

nginx: [emerg] cannot load certificate "/etc/letsencrypt/live/app.mydomain.nl/fullchain.pem": BIO_new_file() failed (SSL: error:02001002:system library:fopen:No such file or directory

I guess the certbot delete command did not fully delete the certificate or something? I am clueless what to do right now...



Solution 1:[1]

You probably used the command $ certbot --nginx and your nginx config file was edited to look for the certificate:

server{
    server_name [your_domain];

    location /static {
        ...
    }

    location / {
        ...
    }

    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/[...]; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/[...]; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/[...]; # managed by Certbot

}

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


    server_name [your_domain];
    listen 80;
    return 404; # managed by Certbot

}

The $ certbot delete will not change it back, so you have to delete the part related to the certificated and change the server_name to your ip address, so it will look like:

server{
    server_name [your ip];

    location /static {
        ...
    }

    location / {
        ...
    }

}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 AlexCiuffa