Force HTTPS access in Apache

Saturday, August 14, 2021 - Posted in

If you configured a certificate to access your Jeedom with HTTPS and you don't want to let the HTTP access available, you can change your Apache settings to redirect HTTP access to the HTTPS automatically.

You'll need to ssh on your Jeedom server and edit the following file:

nano /etc/apache2/sites-available/000-default.conf

The part we want to modify is the virtual host defined for the HTTP port (80)

<VirtualHost *:80>
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html
        ErrorLog /var/www/html/log/http.error
</VirtualHost>

And we'll edit the file to rewrite the HTTP access to the HTTPS access

<VirtualHost *:80>
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html

        RewriteEngine on
        RewriteCond %{SERVER_NAME} =My.JeedomDomain.com
        RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,QSA,R=permanent]

        ErrorLog /var/www/html/log/http.error
</VirtualHost>

You need to replace the "My.JeedomDomain.com" by your actual domain name used to access your Jeedom from outside your network.

When it's done, you just need to enable the rewrite module and restart Apache:

a2enmod rewrite
systemctl restart apache2
comments powered by Disqus