Certbot failed to authenticate some domains (authenticator: nginx)

Hi everyone,

Thanks so much for all your responses! I finally resolved the issue by temporarily disabling the automatic redirect to HTTPS.

For those facing similar problems, here's how I managed to fix it.

Original Certbot-Managed Server Block:

Certbot was automatically redirecting all traffic to HTTPS using the following server block:

server {
    if ($host = mentoring.cehrd.gov.np) {
        return 301 https://$host$request_uri;
    } # managed by Certbot

    listen 80;
    server_name mentoring.cehrd.gov.np;
    return 404; # managed by Certbot
}

Since Certbot needs HTTP for the ACME challenge, I had to temporarily disable the HTTPS redirect. Here's the modified server block:

Temporary Server Block:

server {
    # Temporarily disable HTTPS redirection
    # if ($host = yourwebsite.com) {
    #     return 301 https://$host$request_uri;
    # } # managed by Certbot

    listen 80;
    server_name yourwebsite.com;

    # Allow HTTP for the ACME challenge
    location /.well-known/acme-challenge/ {
        root /your-web-root-path;  # Adjust to your webroot path
    }

    # Comment out the 404 return for Certbot to work
    # return 404; # managed by Certbot
}

Step-by-Step Process:

  1. Save the changes to your NGINX configuration file.

  2. Restart NGINX:

    sudo systemctl restart nginx
    
  3. Run the renewal command:

    sudo certbot renew
    
  4. If you see the error "Another instance of Certbot is already running," kill the running process and try again:

    sudo pkill certbot
    
  5. If the issue persists, remove any Certbot lock files:

    sudo rm /var/log/letsencrypt/.certbot.lock
    sudo rm /var/lib/letsencrypt/lock
    sudo rm /var/lib/letsencrypt/.certbot.lock
    
  6. Ensure the ACME challenge directory exists:

    sudo mkdir -p /your-web-root-path/.well-known/acme-challenge/
    
  7. Set correct permissions for the directory:

    sudo chown -R www-data:www-data /your-web-root-path/.well-known/
    sudo chmod -R 755 /your-web-root-path/.well-known/
    
  8. Reload NGINX:

    sudo systemctl reload nginx
    
  9. Create a test file to verify the ACME challenge directory:

    sudo echo "test" > /your-web-root-path/.well-known/acme-challenge/test-file
    
  10. Check if you can access the test file via your browser or curl:

    curl http://yourwebsite.com/.well-known/acme-challenge/test-file
    

    If it returns "test," your configuration is correct.

  11. Finally, renew the certificate:

    sudo certbot renew
    
  12. Once the renewal is successful, don't forget to revert your server block back to redirect traffic to HTTPS:

    server {
        if ($host = yourwebsite.com) {
            return 301 https://$host$request_uri;
        } # managed by Certbot
    
        listen 80;
        server_name yourwebsite.com;
        return 404; # managed by Certbot
    }
    

That’s it! After following these steps, your certificate should be renewed, and HTTPS redirection will be back in place. I hope this helps anyone facing similar issues!

1 Like