Apache24 SSL(HTTPS) Basic Configuration and Force HTTPS connections
step 1. Edit config file '/usr/local/etc/apache24/httpd.conf' remove the # sign before these lines.
In Apache2.2 [mod_socache_shmcb] is uncommented in httpd.conf by default.From Apache 2.4 [mod_socache_shmcb] is commented
step 2. edit /usr/local/etc/apache24/extra/httpd-ssl.conf file. Modify these lines and configure the appropriate settings.
>>>
step 3. Force HTTPS connections
3 solutions. Redirect Request to SSL.
Using .htaccess files and redirect
Using mod_rewrite
To make sure all traffic is served via SSL:
Using virtual hosts (using redirect)
While the < VirtualHost > solution is recommended because it is simpler and safer
If you wish to redirect users from the non-secure site to the SSL site, you can use an ordinary Redirect directive inside the non-secure VirtualHost:
Edit config file '/usr/local/etc/apache24/httpd.conf' remove the # Include vhosts.conf.
Note: Once the configuration is working as intended, a permanent redirection can be considered. This avoids caching issues by most browsers while testing. The directive would then become:
#LoadModule socache_shmcb_module libexec/apache24/mod_socache_shmcb.so
#LoadModule ssl_module libexec/apache24/mod_ssl.so
#Include etc/apache24/extra/httpd-ssl.conf
In Apache2.2 [mod_socache_shmcb] is uncommented in httpd.conf by default.From Apache 2.4 [mod_socache_shmcb] is commented
step 2. edit /usr/local/etc/apache24/extra/httpd-ssl.conf file. Modify these lines and configure the appropriate settings.
ServerName www.example.com:443 [optional]
ServerAdmin you@example.com [optional]
SSLCertificateFile "/usr/local/etc/apache24/server.crt"
SSLCertificateKeyFile "/usr/local/etc/apache24/server.key"
>>>
ServerName domain_or_ip:443
ServerAdmin master@mail_server
SSLCertificateFile "path/fullchain.pem"
SSLCertificateKeyFile "path/privkey.pem"
step 3. Force HTTPS connections
3 solutions. Redirect Request to SSL.
Using .htaccess files and redirect
Using mod_rewrite
To make sure all traffic is served via SSL:
LoadModule rewrite_module libexec/apache2/mod_rewrite.so
RewriteEngine on
ReWriteCond %{SERVER_PORT} !^443$
RewriteRule ^/(.*) https://%{HTTP_HOST}/$1 [NC,R,L]
Using virtual hosts (using redirect)
While the < VirtualHost > solution is recommended because it is simpler and safer
If you wish to redirect users from the non-secure site to the SSL site, you can use an ordinary Redirect directive inside the non-secure VirtualHost:
Edit config file '/usr/local/etc/apache24/httpd.conf' remove the # Include vhosts.conf.
# Virtual hosts
Include etc/apache24/extra/httpd-vhosts.conf
<virtualhost *:80>
ServerName example.com
Redirect permanent / https://example.com/
</virtualhost>
<virtualhost *:80>
ServerName www.example.com
Redirect permanent / https://www.example.com/
</virtualhost>
Note: Once the configuration is working as intended, a permanent redirection can be considered. This avoids caching issues by most browsers while testing. The directive would then become:
Comments
Post a Comment