Solving letsencrypt Apache vhost config issues
Setting up letsencrypt can be tricky with different variations of apache vhost configs. Here is how to set up letsencrypt Apache vhost config correctly:
(Note: letsencrypt is now certbot. The environment I am using is apache2 by DigitalOcean for Ubuntu/Wordpress VPS, single domain name)
During the interactive set-up of letsencrypt, I was greeted with
1 |
Error: should only be one vhost in /etc/apache2/apache2.conf |
After checking the apache2.conf , I found that there is actually only one vhost in the file:
1 2 3 4 5 6 |
<VirtualHost *:80> ServerAdmin webmaster@paradite DocumentRoot /var/www Servername localhost ServerAlias paradite www.paradite </VirtualHost> |
So why was there an error? I know it’s time to dig out apache documentations. After searching around I found that typically the vhost information is not included in
apache2.conf but rather in a separate
.conf file. So I followed How To Set Up Apache Virtual Hosts on Ubuntu 14.04 LTS to properly set up the vhost.
First I copied default template into a new file:
1 |
sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/paradite.com.conf |
Then inside the new file, cut and paste the vhost information from the apache2.conf. I also did some modifications to the vhost by following the standard. The result is a bit different from the default one above I got from the DigitalOcean:
1 2 3 4 5 6 |
<VirtualHost *:80> ServerAdmin webmaster@paradite DocumentRoot /var/www ServerName paradite.com ServerAlias www.paradite.com </VirtualHost> |
Finally, I have my .conf correctly generated inside /etc/apache2/sites-enabled by issuing
1 |
sudo a2ensite paradite.com.conf |
After that, the letsencrypt client is finally happy and everything worked.
Update: Now the official client for letsencrypt is renamed as certbot, released by eff, hopefully it has resolved this issue by now.
EFF has not fixed the problem, and by all indications they won’t. However, here is a solution that worked for me: https://community.letsencrypt.org/t/cant-renew-certificate-we-were-unable-to-find-a-vhost-with-a-servername-or-address/11675