Solution:
Root Cause: Webroot Directory Permission or Path Mismatch
When using the Certbot webroot plugin, Certbot attempts to drop a temporary verification token file into
${webroot_path}/.well-known/acme-challenge/. If the web server user (
www-data or
nginx) lacks write permissions on the webroot directory, or if the webroot path in
certbot renew configuration does not match the actual document root, the challenge token cannot be created, resulting in an
Invalid Response error.
Diagnostic Verification:
1Inspect Certbot renewal configuration file:
bash
cat /etc/letsencrypt/renewal/yourdomain.com.conf
2Test manual token creation inside the webroot path:
bash
echo "test" > /var/www/html/.well-known/acme-challenge/test.txt
curl -I [http://yourdomain.com/.well-known/acme-challenge/test.txt](http://yourdomain.com/.well-known/acme-challenge/test.txt)
rm /var/www/html/.well-known/acme-challenge/test.txt
Step-by-Step Fix:
1Fix Directory Ownership and Permissions:
Ensure the webroot directory is owned by the web server user with proper write permissions: bash
sudo chown -R www-data:www-data /var/www/html
sudo chmod -R 755 /var/www/html
2Create Missing Challenge Directory Explicitly:
Execute: bash
sudo mkdir -p /var/www/html/.well-known/acme-challenge
sudo chown -R www-data:www-data /var/www/html/.well-known
3Test Renewal in Dry-Run Mode:
Execute: bash
sudo certbot renew --dry-run
Prevention & Long-Term Monitoring:
Ensure deployment scripts preserve correct user ownership and permissions on webroot folders.