Reset project directory of apache web server virtual host having let's encrypt ssl certificate installed

I have a website www.example.com that is hosted on apache2 web server in /var/www/example.com directory and the virtual host config file is

<VirtualHost *:80>
    ServerAdmin admin@gmail.com
    ServerName example.com
    ServerAlias www.example.com
    DocumentRoot /var/www/example.com/public
    <Directory /var/www/example.com/public/>
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    <IfModule mod_dir.c>
        DirectoryIndex index.php index.pl index.cgi index.html index.xhtml >
    </IfModule>
</VirtualHost>

I have installed let's encrypt certificate for this domain.

Now I have to change configuration settings and the config file should be like this:

<VirtualHost *:80>
    ServerAdmin admin@gmail.com
    ServerName example.com
    ServerAlias www.example.com
    DocumentRoot /var/www/example.com/dist //here is the change
    <Directory /var/www/example.com/dist/> //here is the change
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    <IfModule mod_dir.c>
        DirectoryIndex index.php index.pl index.cgi index.html index.xhtml >
    </IfModule>
</VirtualHost>

I have edited the config file and ran command certbot --apache -d example.com -d www.example.com . Chose reinstall and renew both options and the installation was successful in both cases. But when I go to example.com then it shows 404 error . How can I solve my problem?

My domain is: alvismathpoint.com

I ran this command: certbot --apache -d alvismathpoint.com -d www.alvismathpoint.com

It produced this output: Successfully installed certificate

My web server is: apache2

The operating system my web server runs on is: Ubuntu 20.04.1 LTS

My hosting provider is: Digital Ocean

I can login to a root shell on my machine: yes

I'm using a control panel to manage my site: no

The version of my client is:certbot 0.40.0

1 Like

If you look in /etc/apache/sites-enabled/ you should see the configuration file you've edited and you'd also see a similar looking configuration file with -le-ssl.conf at the end. That's the configuration file generated by certbot with your HTTP port 80 VirtualHost as a template.
When you reinstalled the certificate, certbot identified the previously generated configuration file and didn't generate it again: it only updated (if necessary) the links to the certificate/key.

Two ways to fix this:

  • Delete the -le-ssl.conf configuration file and generate it again by doing what you've just done
  • Or a bit more easily I think: manually edit the -le-ssl.conf configuration file just like you did with your HTTP port 80 VirtualHost containing configuration file
3 Likes