How to Redirect HTTP to HTTPS in Nginx

All login credentials transferred over plain HTTP can easily be sniffed by a MITM attacker, but it is not enough to encrypt the login forms. If you are visiting plain HTTP pages while logged in, your session can be hijacked, and not even two-factor authentication will protect you. To protect … Read more

How to Redirect HTTP to HTTPS in apache

Install modules

yum install -y mod_ssl  mod_rewrite

Enable modules

a2enmod rewrite
a2enmod ssl

Method 1

using rewrite module

<VirtualHost *:80>
ServerName www.yourdomain.com
  
RewriteEngine On 
RewriteCond %{HTTPS} !=on 
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]
</VirtualHost>

Method 2

using redirect method

<VirtualHost *:80>
ServerName www.yourdomain.com 
  
Redirect permanent / https://www.yourdomain.com/
</VirtualHost>

Read more