Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

2 Answers

up vote 4 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
add comment

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

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.