Monday, March 13, 2017

Make Apache2 server HTTPS secure

1. Create key and cerificate files.

cd /etc/apache2/
mkdir -p ssl/crt
mkdir -p ssl/key 
cd ssl 
openssl req -newkey  rsa:2048 -nodes -keyout key/vhost2.key    -x509 -days 365 -out crt/vhost2.crt  


2. Configure Virtual host in the file /etc/apache2/sites-available/000-default.conf


...
<VirtualHost *.443>        
        DocumentRoot /var/www/secure
        ServerName vhost1.yourdomain.com
        # DirectoryIndex index.php
        ErrorLog /var/log/apache2/vhost1-error.log
        CustomLog /var/log/apache2/vhost1-access.log combined
        SSLEngine On
        SSLCertificateFile /etc/apache2/ssl/crt/vhost2.crt
        SSLCertificateKeyFile /etc/apache2/ssl/key/vhost2.key
        <Location />
        SSLRequireSSL On
        SSLVerifyClient optional
        SSLVerifyDepth 1
        SSLOptions +StdEnvVars +StrictRequire
        </Location>
        <Directory "/var/www/vhost1">
                Options Indexes FollowSymLinks MultiViews
                AllowOverride None
                Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
                Order allow,deny
                AddHandler cgi-script .py
                AddHandler default-handler .html .htm
                Allow from all
         </Directory>
</VirtualHost>


3. Install modes
    sudo a2enmod rewrite
    sudo a2enmod ssl 


3.  Restart Apache2 

    sudo service apache2 restart 

No comments:

Post a Comment

Followers

About Me