Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

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

This is how I have set up a virtual host:

<VirtualHost mysite> 
  <Directory "/Users/myusername/sitefolder"> 
    Options +FollowSymlinks
    AllowOverride All 
    Order Allow,Deny
    Allow from all
  </Directory> 
  DocumentRoot "/Users/myusername/sitefolder"
  ServerName mysite
  SSLEngine on
  SSLCertificateFile /Users/myusername/certs/server.crt
  SSLCertificateKeyFile /Users/myusername/certs/server.key
</VirtualHost>

With this configuration, I can view my site only with https, but not http. When I turn SSLEngine off then I cannot view my site with https, but http works fine.

How can I adjust the above lines so that I am able to see my site using both http and https?

I using OSX Lion, but I don't think it matters that much.

Thanks.

share|improve this question
up vote 7 down vote accepted

You need to create two virtual hosts thus:

<VirtualHost mysite:80> 
  <Directory "/Users/myusername/sitefolder"> 
    Options +FollowSymlinks
    AllowOverride All 
    Order Allow,Deny
    Allow from all
  </Directory> 
  DocumentRoot "/Users/myusername/sitefolder"
  ServerName mysite
</VirtualHost>


<VirtualHost mysite:443> 
  <Directory "/Users/myusername/sitefolder"> 
    Options +FollowSymlinks
    AllowOverride All 
    Order Allow,Deny
    Allow from all
  </Directory> 
  DocumentRoot "/Users/myusername/sitefolder"
  ServerName mysite
  SSLEngine on
  SSLCertificateFile /Users/myusername/certs/server.crt
  SSLCertificateKeyFile /Users/myusername/certs/server.key
</VirtualHost>

The first is a regular HTTP host, while the second handles your HTTPS traffic.

share|improve this answer
    
Is there any way to move the common code into a different file and #include it to make maintenance easier? – Wallacoloo Dec 18 '13 at 6:11

You also probably want to use Include directive so you don't have to duplicate config between your two vhosts - http://httpd.apache.org/docs/2.2/mod/core.html#include.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .