OutRight Utils

This article is focused on Creating Virtual Hosts on Ubuntu using Letsencrypt Certificates, we learned to generate SSL files using free Letsencrypt. Now using them we are going to make a virtual host. Replace your_domain.com with your actual domain.

Virtual Hosts

Just follow steps and copy code at this file.

cd /etc/apache2/sites-available
nano your_domain.conf

Now copy both sections to this file, save this file.

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
                ServerName  your_domain.com
                ServerAlias www.your_domain.com
                DocumentRoot /web/html
#		Redirect / https://your_domain.com/
		<directory /web/html >
                	Options Indexes FollowSymLinks
                	AllowOverride All
                	Order allow,deny
                	Allow From All
        	</directory>
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
<VirtualHost *:443>
                SSLEngine on
		SSLCertificateFile /etc/letsencrypt/live/your_domain.com/cert.pem
		SSLCertificateKeyFile /etc/letsencrypt/live/your_domain.com/privkey.pem
		SSLCertificateChainFile /etc/letsencrypt/live/your_domain.com/chain.pem
		ServerAdmin webmaster@localhost
                ServerName  your_domain.com
                ServerAlias www.your_domain.com
                	<directory /web/html >

                        Options Indexes FollowSymLinks
                        AllowOverride All
                        Order allow,deny
                        Allow From All                  
	</directory>

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

Now run this to enable your newly created virtual host.

a2ensite your_domain.conf

Time to restart Apache

service apache2 restart

Now go to your browser, your site your_domain.com must start listening to this newly created virtual host. Horray!

To be summarised, It was horrible before Letsencrypt, Letsencrypt makes life so easy to call our websites to Secure!

Related Posts