By accident I stumbled across a website with an expired certificate from Letsencrypt. After a manual renewal (certbot renew) was attempted, the following error message was shown:
Processing /etc/letsencrypt/renewal/app.example.com.conf
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Cert is due for renewal, auto-renewing...
Plugins selected: Authenticator webroot, Installer None
Renewing an existing certificate
Performing the following challenges:
http-01 challenge for app.example.com
Waiting for verification...
Cleaning up challenges
Attempting to renew cert (app.example.com) from /etc/letsencrypt/renewal/app.example.com.conf produced an unexpected error: Failed authorization procedure. app.example.com (http-01): urn:ietf:params:acme:error:unauthorized :: The client lacks sufficient authorization :: Invalid response from https://app.example.com/.well-known/acme-challenge/m_Fb2jvABeDHAYQLZ52hfDO_LIo5_dLdG5H8RysyNwM [XXX.XXX.XXX.XXX]: "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\n<html><head>\n<title>404 Not Found</title>\n</head><body>\n<h1>Not Found</h1>\n<p". Skipping.
The following certs could not be renewed:
/etc/letsencrypt/live/app.example.com/fullchain.pem (failure)
Because another admin set up this particular vhost a couple of months ago, I needed to check and verify the vhost config. And indeed, something caught my eye on the http/port 80 listener:
root@webserver:~# cat /etc/apache2/sites-enabled/app.example.com.conf
<VirtualHost *:80>
ServerName app.example.com
DocumentRoot /srv/www/app.example.com
Alias /.well-known/ "/var/www/letsencrypt/.well-known/"
<Directory "/var/www/letsencrypt/">
AllowOverride None
Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
Require method GET POST OPTIONS
</Directory>
# Rewrite Rules
RewriteEngine on
RewriteRule "^/?(.*)" "https://app.example.com/$1" [L,R,NE]
# Logging
ErrorLog /var/log/apache2/app.example.com.error.log
CustomLog /var/log/apache2/app.example.com.access.log combined
</VirtualHost>
[...followed by ssl config...]
The RewriteRule is a general rule to redirect all requests to the https site. The Letsencrypt bot however tries to access the relative path /.well-known/acme-challenge using the HTTP method, not HTTPS.
A quick solution to this is to use a rewrite condition before the RewriteRule (found on serverfault):
# Rewrite Rules
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/\.well\-known/acme\-challenge/
RewriteRule "^/?(.*)" "https://app.example.com/$1" [L,R,NE]
With this added condition, the RewriteRule is only applied if the condition is matched. In this case the RewriteCond checks for the requested relative path. Only if the relative path is not /.well-known/acme-challenge, do the http to https redirect. After reloading the new vhost config, the certificate could be renewed again:
root@webserver:~# certbot renew
[...]
Processing /etc/letsencrypt/renewal/app.example.com.conf
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Cert is due for renewal, auto-renewing...
Plugins selected: Authenticator webroot, Installer None
Renewing an existing certificate
Performing the following challenges:
http-01 challenge for app.example.com
Waiting for verification...
Cleaning up challenges
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
new certificate deployed without reload, fullchain is
/etc/letsencrypt/live/app.example.com/fullchain.pem
No comments yet.
AWS Android Ansible Apache Apple Atlassian BSD Backup Bash Bluecoat CMS Chef Cloud Coding Consul Containers CouchDB DB DNS Database Databases Docker ELK Elasticsearch Filebeat FreeBSD Galera Git GlusterFS Grafana Graphics HAProxy HTML Hacks Hardware Icinga Influx Internet Java KVM Kibana Kodi Kubernetes LVM LXC Linux Logstash Mac Macintosh Mail MariaDB Minio MongoDB Monitoring Multimedia MySQL NFS Nagios Network Nginx OSSEC OTRS Office PGSQL PHP Perl Personal PostgreSQL Postgres PowerDNS Proxmox Proxy Python Rancher Rant Redis Roundcube SSL Samba Seafile Security Shell SmartOS Solaris Surveillance Systemd TLS Tomcat Ubuntu Unix VMWare VMware Varnish Virtualization Windows Wireless Wordpress Wyse ZFS Zoneminder