8

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.

7

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.

  • Is there any way to move the common code into a different file and #include it to make maintenance easier? – Ponkadoodle Dec 18 '13 at 6:11
1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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