Showing posts with label Apache2. Show all posts
Showing posts with label Apache2. Show all posts

Tuesday, April 5, 2016

In this post I'll explain how we can redirect all HTTP traffic to HTTPS. Here I'm using Apache2 and its rewrite module to achieve this.

You can refer the following configuration from apache.

RewriteEngine on

RewriteCond %{HTTPS} !=on
# This checks to make sure the connection is not already HTTPS
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]

In the above configurations I'm rewriting all HTTP traffic to its HTTPS URL.

http://yenlo.com/t  ==> https://yenlo.com/t

Full Apache configs will look like following.

<VirtualHost mod_rewrite.c *:80>
        ServerName yenlo.com
        ServerAlias yenlo.com

RewriteEngine on

RewriteCond %{HTTPS} !=on
# This checks to make sure the connection is not already HTTPS
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]

</VirtualHost>

<Virtualhost *:443>
ServerName yenlo.com
ServerAlias yenlo.com
ProxyPreserveHost On
# ProxyRequests On
SSLEngine On
SSLProxyEngine On
SSLProxyVerify none
SSLProxyCheckPeerCN off
SSLProxyCheckPeerName off
SSLCertificateFile /etc/apache2/ssl/apache.crt
SSLCertificateKeyFile /etc/apache2/ssl/apache.key

ProxyPass /t https://10.100.5.112:9443/t
ProxyPassReverse /t https://10.100.5.112:9443/t

</Virtualhost>


Thanks for reading and please drop a comment if you have any queries.

Monday, August 3, 2015

In this post I'll explain you how to install Apache2 Server and enable SSL for Apache2. Here I'm working on ubuntu 14.04 LTS. So lets get started.

Installing Apache2

First Lets update the Ubuntu repositories.

sudo apt-get install udgrade
sudo apt-get install update

Now Lets install apache2

sudo apt-get install apache2

Enable SSL in Apache Server

Create a directory as shown below,

sudo mkdir /etc/apache2/ssl

Now go to the created directory

cd /etc/apache2/ssl

Creating the certificates. 

Execute the following commands to create the key

sudo openssl genrsa -out "apache.key" 2048

Execute the the following to create the certificate sign request

sudo openssl req -new -key "apache.key" -out "apache.csr"

Fill information similar to following whencreating the CSR



Lets Sign the Key

sudo openssl x509 -req -days 3650 -in "apache.csr" -signkey "apache.key" -out "apache.crt"


Now Enable SSL module, if this is module is not installed you will have to install it :). Execute following to enable SSL in apache2

sudo a2enmod ssl

Now add the following to 000-default.conf in sites-enabled which is located at /etc/apache2/sites-enabled/000-default.conf

<VirtualHost *:443>
   
    SSLEngine on
    SSLCertificateFile  /etc/apache2/ssl/apache.crt
    SSLCertificateKeyFile /etc/apache2/ssl/apache.key

</VirtualHost>

Note : You can define server names and other parameters when configurin this further, above is the minimum content that is required.

Now restart the server.


sudo service apache2 restart

That is it, Now you are good to go :).

Please drop a comment if you have any Queries.


Subscribe to RSS Feed Follow me on Twitter!