Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I'm trying to acheive the following:

http:// site.com -> main site (with www.site.com rewriting with no www)

https:// predeploy.site.com -> second site (password protected and SSL)

https:// site.com -> connection refused

http:// predeploy.site.com -> connection refused

The DNS for the subdomains is done with A records rather than CNAMEs, as they are apparently the preferred method for the Linode name servers. Both site.com and predeploy.site.com resolve to the same IP.

I have two vhosts set up:

NameVirtualHost *:80
<VirtualHost *:80>
    ServerName site.com
    ServerAlias www.site.com
    DocumentRoot /var/www/site.com
    RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
    RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
</VirtualHost>

NameVirtualHost *:443
<VirtualHost *:443>
    ServerName predeploy.site.com
    DocumentRoot /var/www/predeploy.site.com
    SSLEngine on
    ... # Basic auth and SSL stuff, which works
</VirtualHost>

The problem is that https:// site.com serves up the second site (same as https:// predeploy.site.com, and requires authentication), and http:// predeploy.site.com serves up the main site (same as http:// site.com). I believe this means the vhosts are wrong. How do I fix them?

share|improve this question
    
First, do not mix asterisk and port number. Specify ip or hostname instead of using asterisk and let apache listen on it listen hostname:80 and listen hostname:443 –  Ency Apr 3 '11 at 21:19

1 Answer 1

It behaves like you have configured it. let me explain:

SSL is based on port, and "NameVirtualHost" does not really exist under SSL, unless you use UCC certificates. This means, that if you use the same IP address for both sites, it will always show your configured SSL site, since it binds on the port.

You did not create a VirtualHost for predeploy.site.com for port 80, meaning that it will default to the first one. If you want predeploy without SSL to redirect to predeploy WITH ssl, you will need to create a virtualhost on port 80 for it and then do a redirect within that virtual host.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.