I created ssl certificate for myDomain.com
Hence I see following 3 files under /etc/apache2/sites-enabled
in Ubuntu
example.com-le-ssl.conf example.com.conf example.conf
My example.com.conf
looks like this
<VirtualHost *:80>
ServerAdmin admin@example
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/example.com
JKMount /* ajp13_worker
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
RewriteEngine on
RewriteCond %{SERVER_NAME} =www.example.com [OR]
RewriteCond %{SERVER_NAME} =example.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
Now, if I enter http://www.example.com
it is redirected to https://www.example.com
But if someone finds out my server ip address and enter http://<myIpAddress>
the content is served as non-https
So I added this in addition to above virtualHost chunk
<VirtualHost myIpAddr:80>
ServerAdmin admin@example
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/example.com
JKMount /* ajp13_worker
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
RewriteEngine on
RewriteCond %{SERVER_NAME} =myIpAddr [OR]
RewriteCond %{SERVER_NAME} =myIpAddr:80
RewriteRule ^ https://www.example.com%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
But still when I enter http://myIpAddr:80
or http://myIpAddr
I see this