====== Apache convert http to https ====== ==== enable ==== Enable Apache module named: Mod_ssl and Mod_rewrite. a2enmod ssl a2enmod rewrite vi /etc/apache2/apache2.conf AllowOverride All # mkdir /etc/apache2/certificate # cd /etc/apache2/certificate # openssl req -new -newkey rsa:4096 -x509 -sha256 -days 365 -nodes -out apache-certificate.crt -keyout apache.key Generating a RSA private key ............++++ .......................................................++++ writing new private key to 'apache.key' ----- You are about to be asked to enter information that will be incorporated into your certificate request. What you are about to enter is what is called a Distinguished Name or a DN. There are quite a few fields but you can leave some blank For some fields there will be a default value, If you enter '.', the field will be left blank. ----- Country Name (2 letter code) [AU]:BR State or Province Name (full name) [Some-State]:Rio de Janeiro Locality Name (eg, city) []: Organization Name (eg, company) [Internet Widgits Pty Ltd]:TechExpert Organizational Unit Name (eg, section) []: Common Name (e.g. server FQDN or YOUR name) []:200.200.200.200 Email Address []: # vi /etc/apache2/sites-enabled/000-default.conf Here is the file, before our configuration. ServerAdmin webmaster@localhost DocumentRoot /var/www/html ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined Here is the file, after our configuration. ServerAdmin webmaster@localhost DocumentRoot /var/www/html ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined SSLEngine on SSLCertificateFile /etc/apache2/certificate/apache-certificate.crt SSLCertificateKeyFile /etc/apache2/certificate/apache.key Optionally, you may want to redirect HTTP users to the HTTPS version of your website. RewriteEngine On RewriteCond %{HTTPS} !=on RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R=301,L] ServerAdmin webmaster@localhost DocumentRoot /var/www/html ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined SSLEngine on SSLCertificateFile /etc/apache2/certificate/apache-certificate.crt SSLCertificateKeyFile /etc/apache2/certificate/apache.key Restart the Apache service service apache2 restart