Ubuntu 20.04 HTTP to HTTPS redirection

Ubuntu 20.04 HTTP to HTTPS redirection

As a bonus step, we will redirect HTTP traffic to HTTPS.

We will edit 192.168.60.3.conf file we created above in this guide.

sudo nano /etc/apache2/sites-available/your_domain_or_ip.conf

At the bottom of the file we will create another block with following


    ServerName your_domain_or_ip
    Redirect / https://your_domain_or_ip/

This is how my config file looks like:


    ServerName pihi
    ServerAlias www.pihi
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/pihi
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined


   ServerName localhost
   DocumentRoot /var/www/pihi

   SSLEngine on
   SSLCertificateFile /etc/ssl/certs/apache-selfsigned.crt
   SSLCertificateKeyFile /etc/ssl/private/apache-selfsigned.key


    ServerName localhost
    Redirect / https://localhost/

 

Marek Mihók