I just installed lets encrypt (using this guide). In the step where I could choose to force all requests to redirect to https and I chose no…
How can now I edit the Apache2 configuration in /etc/apache2/sites-available to redirect all the http to https only for this specific domain?
After running sudo certbot --apache -d scti.gr -d www.scti.gr I have 2 .conf files in the sites-available folder. One that I had created scti.gr.conf and now I have one more scti.gr-le-ssl.conf
Should I edit my scti.gr.conf as:
<VirtualHost *:80>
ServerName www.example.com
Redirect / https://www.example.com/
</VirtualHost>
<VirtualHost *:443>
//copy here the content that exists in scti.gr-le-ssl.conf
</VirtualHost>
My domain is: scti.gr
My web server is: Server version: Apache/2.4.18 (Ubuntu), Server built: 2017-09-18T15:09:02
The operating system my web server runs on is: Ubuntu 16.04.3 LTS
My hosting provider, if applicable, is: Vultr
I can login to a root shell on my machine: yes
I’m using a control panel to manage my site: no
Hi @yaylitzis,
To give you the right advice, could you please post the current and unedited conf for scti.gr.conf & scti.gr-le-ssl.conf files?.
Cheers,
sahsanu
I would do the redirect in your scri.gr.conf, like you have already done. Don’t copy contents from the autogenerated config file into the other one, as both will be read by the webserver anyway.
Thank you @sahsanu !
The scti.gr.conf contains (without the comments):
<VirtualHost *:80>
ServerAdmin myemail@domain.com
ServerName scti.gr
ServerAlias www.scti.gr
DocumentRoot /var/www/html/scti.gr
ErrorLog ${APACHE_LOG_DIR}/sctigr-error.log
CustomLog ${APACHE_LOG_DIR}/sctigr-access.log combined
</VirtualHost>
and the scti.gr-le-ssl.conf contains (without the comments):
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerAdmin myemail@domain.com
ServerName scti.gr
ServerAlias www.scti.gr
DocumentRoot /var/www/html/scti.gr
ErrorLog ${APACHE_LOG_DIR}/sctigr-error.log
CustomLog ${APACHE_LOG_DIR}/sctigr-access.log combined
SSLCertificateFile /etc/letsencrypt/live/scti.gr/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/scti.gr/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
</IfModule>
Ok, then you only need to edit scti.gr.conf file:
<VirtualHost *:80>
ServerAdmin myemail@domain.com
ServerName scti.gr
ServerAlias www.scti.gr
DocumentRoot /var/www/html/scti.gr
ErrorLog ${APACHE_LOG_DIR}/sctigr-error.log
CustomLog ${APACHE_LOG_DIR}/sctigr-access.log combined
Redirect permanent / https://scti.gr/
</VirtualHost>
Above conf will redirect requests to http://scti.gr and http://www.scti.gr to https://scti.gr if you for example want to redirect http://scti.gr to https://scti.gr and http://www.scti.gr to https://ww.scti.gr use this conf:
<VirtualHost *:80>
ServerAdmin myemail@domain.com
ServerName scti.gr
ServerAlias www.scti.gr
DocumentRoot /var/www/html/scti.gr
ErrorLog ${APACHE_LOG_DIR}/sctigr-error.log
CustomLog ${APACHE_LOG_DIR}/sctigr-access.log combined
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>
</VirtualHost>
I hope this helps.
Cheers,
sahsanu
@sahsanu Thanks a lot for your full explained answer!!!