Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to acheive the following:

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

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

https:// -> connection refused

http:// -> 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 and resolve to the same IP.

I have two vhosts set up:

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

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

The problem is that https:// serves up the second site (same as https://, and requires authentication), and http:// serves up the main site (same as http:// 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

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 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


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.