# How to enable multiple secure vhosts on the same IP, port and domain.
# 
# 0) All hosts on the same IP must use the same wildcard SSL certificate.
#
# 1) Without the port number on the ServerName users would randomly see a 
#    "12263 error" over SSL. To be safe I added it on all vhosts.
#
# 2) With PHP - if you want to use Environment Vars from $_SERVER, you might 
#    have to set them yourself. Apache lies to PHP when on SSL.
#
# 3) Only enable SSL once per Cert
#

# Enable name based hosts for the IP and ports you plan to use
NameVirtualHost 192.168.0.2:80
NameVirtualHost 192.168.0.2:443

# WWW.EXAMPLE.COM

<VirtualHost 192.168.0.2:80>    	
	ServerName www.example.com:80       
	DocumentRoot "/var/www/example.com/www"
</VirtualHost>

# SECURE WWW.EXAMPLE.COM

<VirtualHost 192.168.0.2:443>
	# Without the port number on the ServerName users would randomly see a "12263 error"
	ServerName www.example.com:443    
	DocumentRoot "/var/www/example.com/www"

	# Enable SSL (only once per cert)
	SSLEngine on
	SSLCertificateFile /var/ssl/example.com/STAR_example_com.crt
	SSLCertificateKeyFile /var/ssl/example.com/STAR_example.key
	SSLCACertificateFile /var/ssl/example.com/STAR_example.gd_bundle.crt
	
	
	# Apache lies to PHP about these environtment variables
	# Despite the browser being happy on https (443)
	# 'HTTPS' isn't set in the PHP $_SERVER array and 'SERVER_PORT' is set to 80
	
	SetEnv HTTPS on
	SetEnv SERVER_PORT 443

</VirtualHost>

# ADMIN.EXAMPLE.COM REDIRECT

<VirtualHost 192.168.0.2:80>
	ServerName example.com:80
	redirect permanent / https://admin.example.com/	
</VirtualHost>

# SECURE ADMIN.EXAMPLE.COM

<VirtualHost 192.168.0.2:443>
	# Without the port number on the ServerName users would randomly see a "12263 error"
	ServerName admin.example.com:443    
	DocumentRoot "/var/www/admin_example.com/www"

	# DO NOT turn the SSL Engine on or configure the SSL Certs, it is already done
	
	# Apache lies to PHP about these environtment variables
	# Despite the browser being happy on https (443)
	# 'HTTPS' isn't set in the PHP $_SERVER array and 'SERVER_PORT' is set to 80
	
	SetEnv HTTPS on
	SetEnv SERVER_PORT 443

</VirtualHost>
