SSL enabled virtual host in OS X Mavericks

I have several virtual hosts installed on my local dev machine using Apache / 2.2.24 on OS X 10.9 (Mavericks).

My http-vhosts.conf file (which is configured to download via httpd.conf is as follows:

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 also configured the / etc / vhosts file containing this line:

 127.0.0.1 testsite2.dev 

I want to be able to use testite2.dev over SSL (https). I tried several vhosts configuration file configurations with no luck.

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

I tried the following configuration and several 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 for a virtual host to listen on port 80 and port 443 on the local computer?

+6
source share
1 answer

I figured out how to do it. I just skipped a few directives to show where my certificate and key are. Here is 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> 

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 do not have a certificate and key installed, you can create your own by following the following tutorial:

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.

+15
source

Source: https://habr.com/ru/post/957615/


All Articles