Tuesday, March 17, 2009

Apache 2.2 SSL Setup including redirect

Usually done in /etc/httpd/conf.d/ssl.conf

I comment out the virtual host in the above file and add the relevant data to my file.

NameVirtualHost 192.168.1.1:80
NameVirtualHost 192.168.1.1:443

<VirtualHost 192.168.1.1:80>
ServerName whatever.yoursite.com
DocumentRoot "/export/web/html"
ErrorLog logs/whatever.yoursite.com_error_log
CustomLog logs/whatever.yoursite.com_access_log common

Redirect / https://whatever.yoursite.com/

</VirtualHost>

<VirtualHost 192.168.1.1:443>
ServerName whatever.yoursite.com
DocumentRoot "/export/web/html"
ErrorLog logs/whatever.yoursite.com_error_log
CustomLog logs/whatever.yoursite.com_access_log common
##LogLevel debug
<Directory "/export/web/html">
Options FollowSymlinks
AllowOverride None
Order allow,deny
Allow from all
AuthName "LDAP Authorization"
AuthType Basic

### The next 2 lines are required in Apache 2.2
AuthBasicProvider ldap
AuthzLDAPAuthoritative off

AuthLDAPBindDN "ldapuser@ad_domain"
AuthLDAPBindPassword "password"
AuthLDAPURL "ldap://AD_Domain_Controller/ou=Users,dc=yoursite,dc=com?sAMAccountName?sub"

### Either use valid-user or ldap-user
#require valid-user
require ldap-user user1 user2 user3 user4
require ldap-user user5 user6 user7 user8

satisfy all
</Directory>
SSLEngine on
SSLProtocol all -SSLv2
SSLCipherSuite ALL:!ADH:!EXPORT:!SSLv2:RC4+RSA:+HIGH:+MEDIUM

SSLCertificateFile /etc/httpd/conf/ssl/yoursite.com.crt
SSLCertificateKeyFile /etc/httpd/conf/ssl/yoursite.com.key
SSLCertificateChainFile /etc/httpd/conf/ssl/bundle.crt

RewriteEngine On
RewriteCond %{REQUEST_METHOD} ^TRACE
RewriteRule .* - [F]

</VirtualHost>