我在OS X 10.9(Mavericks)上运行Apache / 2.2.24的本地开发机器上设置了一些虚拟主机。
我的http-vhosts.conf文件(配置为通过httpd.conf加载)如下所示:
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>
我还将/ etc / vhosts文件配置为包含以下行:
127.0.0.1 testsite2.dev
我希望能够通过SSL(https)使用testsite2.dev。我已经尝试了多个配置的vhosts配置文件而没有运气。
使用当前配置,转到http://testsite2.dev会拉出我期望的页面,而https://testsite2.dev指向apache主页/Library/WebServer/Documents/index.html.en
我尝试了以下配置,以及其他多个不起作用的配置:
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>
是否可以让虚拟主机侦听本地计算机上的端口80和端口443?
答案 0 :(得分:15)
我想出了如何做到这一点。我只是缺少一些指令来显示我的证书和密钥所在的位置。这是我添加的内容:
<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>
在上下文中显示,我的http-vhosts.conf文件如下所示:
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>
如果您没有安装证书和密钥,可以按照以下教程创建自己的证书:
http://www.cfdad.com/2012/12/12/creating-a-self-signed-ssl-cert-for-mac-osx-mountain-lion-apache/
它应该适用于Mountain Lion和Mavericks。