Second virtual host not working

Posted April 5, 2021 197 views
LAMP Stack


I try to set a second virtual host up on the same droplet. I have a LAMP stack.

The second virtual host points to the first site which I don’t want it to.

My /etc/apache2/sites-available/

<VirtualHost *:80>
DocumentRoot /var/www/html/
RewriteEngine on
RewriteCond %{SERVERNAME} [OR]
RewriteCond %{SERVERNAME}
RewriteRule ^ https://%{SERVERNAME}%{REQUEST_URI} [END,NE,R=permanent]

My DNS records: A to IP, A to IP with www, 3 ns to Digital Ocean, AAAA to IP, AAAA to IP with www.

I have pointed my DNS from namecheap (my domain) to Digital Oceans nameservers.

Any help on how to get my second site up will be greatly appreciated, thanks!


edited by bobbyiliev
1 comment
  • Hi bobbyiliev,

    Thanks for your answer!

    I did what you wrote, the cert is good and now I have another problem.

    When I run my site: it hangs and then I can see it ends on an old second host I had on the domainname in the browser. I have no idea where it get that information from…


These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
1 answer

Hi there,

It looks like that you have an HTTP to HTTPS redirect defined in your Vhost, however, the domain name does not have a SSL certificate installed.

You would need to first remove these lines here:

RewriteEngine on
RewriteCond %{SERVERNAME} [OR]
RewriteCond %{SERVERNAME}
RewriteRule ^ https://%{SERVERNAME}%{REQUEST_URI} [END,NE,R=permanent]

Then restart Apache:

sudo systemctl restart apache2

After that follow the steps from this tutorial here on how to install a Let’s Encrypt SSL certificate:

After that during the installation certbot will ask you if you want to setup the redirect again.

Hope that this helps!

by Erika Heidi
Let's Encrypt is a Certificate Authority (CA) that facilitates obtaining and installing free TLS/SSL certificates, thereby enabling encrypted HTTPS on web servers. Currently, the entire process of obtaining and installing a certificate is fully automated on both Apache and Nginx with the use of Certbot. In this guide, we'll use Certbot to obtain a free SSL certificate for Apache on Ubuntu 20.04, and make sure this certificate is set up to renew automatically.