Apache: rewrite port 80 and 443 - multiple SSL vhosts setup
Posted
by Benjamin Jung
on Server Fault
See other posts from Server Fault
or by Benjamin Jung
Published on 2010-04-30T22:48:23Z
Indexed on
2010/04/30
22:59 UTC
Read the original article
Hit count: 396
SETUP:
- multiple SSL domains are configured on a single IP, by using vhosts with different port numbers (on which Apache listens)
- Apache 2.2.8 on Windows 2003 (no comments on this pls)
- too many Windows XP users so SNI isn't an option yet
There may be reasons why it's wrong to use this approach, but it works for now.
vhosts setup:
# secure domain 1
<VirtualHost IP:443>
SSL stuff specifying certificate etc.
ServerName domain1.org
</VirtualHost>
# secure domain 2
<VirtualHost IP:81>
SSL stuff for domain2.org
ServerName domain2.org
</VirtualHost>
GOAL: Some folders inside the domain2.org docroot need to be secure. I used a .htaccess file to rewrite the URL to https on port 81:
RewriteEngine On
RewriteCond %{SERVER_PORT} !^81$
RewriteRule (.*) https://%{HTTP_HOST}:81%{REQUEST_URI} [R]
Suppose I put the .htaccess in the folder 'secfolder'.
When accessing http://domain2.org/secfolder
this gets succesfully rewritten to https://domain2.org:81/secfolder.
ISSUE:
When accessing https://domain2.org/secfolder
(without port 81), the certificate from the first vhost (domain1.org) is used and the browser complains that the site is insecure because the certificate is not valid for domain2.org.
I thought that RewriteCond %{SERVER_PORT} !^81$
would also rewrite https://domain2.org
to https://domain2.org:81
, but it doesn't. It seems that the .htaccess file is not being used at all in this case.
At this point I am not sure how to apply a RewriteRule to https://domain2.org
.
I tried creating an additional vhost for domain2 on port 443 before the one for domain1.org, but Apache seems to choke on that. I hope someone of you has an idea how to approach this. TIA.
© Server Fault or respective owner