Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Virtual Host With SSL Support on OS X Mavericks

I have a few virtual hosts setup on my local dev machine running Apache/2.2.24 on OS X 10.9 (Mavericks).

My http-vhosts.conf file (that is configured to load through httpd.conf looks like this:

NameVirtualHost *:80

<VirtualHost *:80>
   DocumentRoot "/Library/WebServer/Documents"
   ServerName localhost
</VirtualHost>

<VirtualHost *:80>
   DocumentRoot "/Users/me/Sites/testsite.com
   ServerName testsite.dev
</VirtualHost>

<VirtualHost *:80>
   DocumentRoot "/Users/me/Sites/testsite2.com
   ServerName testsite2.dev
</VirtualHost>

I have also configured my /etc/vhosts file to contain this line:

127.0.0.1       testsite2.dev

I want to be able to use the testsite2.dev over SSL (https). I have tried multiple configurations of the vhosts config file with no luck.

With this current configuration, going to http://testsite2.dev pulls up the page I expect while https://testsite2.dev points to the apache home page at /Library/WebServer/Documents/index.html.en

I have tried the following configuration, and multiple others, that do not work:

NameVirtualHost *:80
NameVirtualHost *:443

<VirtualHost *:80>
   DocumentRoot "/Library/WebServer/Documents"
   ServerName localhost
</VirtualHost>

<VirtualHost *:80>
   DocumentRoot "/Users/me/Sites/testsite.com
   ServerName testsite.dev
</VirtualHost>

<VirtualHost *:80 *:443>
   DocumentRoot "/Users/me/Sites/testsite2.com
   ServerName testsite2.dev
</VirtualHost>

Is it possible to have a virtual host listen on port 80 and port 443 on a local machine?

like image 726
ChiCgi Avatar asked Nov 07 '13 18:11

ChiCgi


People also ask

Where is Vhost file in Mac?

By default, the Apache Virtual Host configuration on Mac OS X is located in a single file: /etc/apache2/extra/httpd-vhosts.


1 Answers

I figured out how to do this. I was simply missing a few directives to show where my certificate and key are located. Here's what I added:

<VirtualHost *:443>
   SSLEngine on
   SSLCertificateFile /private/etc/apache2/ssl/server.crt
   SSLCertificateKeyFile /private/etc/apache2/ssl/server.key
   DocumentRoot "/Users/me/Sites/testsite2.com"
   ServerName testsite2.dev
</VirtualHost>

Shown in context, my http-vhosts.conf file looked like this:

Listen  *:443
NameVirtualHost *:80
NameVirtualHost *:443

<VirtualHost *:80>
   DocumentRoot "/Library/WebServer/Documents"
   ServerName localhost
</VirtualHost>

<VirtualHost *:80>
   DocumentRoot "/Users/me/Sites/testsite.com
   ServerName testsite.dev
</VirtualHost>

<VirtualHost *:443>
   SSLEngine on
   SSLCertificateFile /private/etc/apache2/ssl/server.crt
   SSLCertificateKeyFile /private/etc/apache2/ssl/server.key
   DocumentRoot "/Users/me/Sites/testsite2.com"
   ServerName testsite2.dev
</VirtualHost>

If you don't have a certificate and key installed, you can create your own by following a tutorial like this one:

http://www.cfdad.com/2012/12/12/creating-a-self-signed-ssl-cert-for-mac-osx-mountain-lion-apache/

It should work on both Mountain Lion and Mavericks.

like image 64
ChiCgi Avatar answered Oct 13 '22 00:10

ChiCgi