How to configure HTTPS on Apache 2

Configure HTTPS on Apache 2
1. Create httpd.pem & httpd.key file
# mkdir /data/www/project/ssl/
# openssl req -new -x509 -days 365 -nodes -out /data/www/project/ssl/httpd.pem -keyout /data/www/project/ssl/httpd.key

2. Configure apache2 (httpd.conf)
Listen 80
<VirtualHost *:80>
DocumentRoot “/data/www/project/web”
Options  FollowSymLinks  -ExecCGI -Includes -Indexes
DirectoryIndex index.php
<Directory “/data/www/project/web”>
AllowOverride All
Allow from All
</Directory>
</VirtualHost>
## HTTPS ##
Listen 443
NameVirtualHost *:443
<VirtualHost *:443>
SSLEngine On
SSLCertificateFile /data/www/project/ssl/httpd.pem
SSLCertificateKeyFile /data/www/project/ssl/httpd.key
#ServerAdmin info@mydomain.com
#ServerName xxxx
DocumentRoot /data/www/project/web
#ErrorLog /data/www/project/log/
#CustomLog /data/www/project/log/access.log combined
</VirtualHost>
3. Configure redirect SSL with .htaccess
# vim /data/www/project/web/.htaccess
Options +FollowSymLinks +ExecCGI
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} !on
RewriteRule ^(.*)$ https://%{SERVER_NAME}/$1 [R,L]
</IfModule>
4. Note:
- Enable mod_rewrite
- Install openssl (here)


No comments:

Post a Comment