很抱歉冒出这样的旧帖子,但为了帮助其他 Google 员工,我想分享一下我是如何处理它的:
我的本地主机上有几个虚拟主机,比如:localhost
、、foo.com
bar.com
这是我的笔记本电脑(macosx)上的本地主机站点,我可以使用自签名证书,因此所有虚拟主机的 ssl 部分都是相同的......
我所做的是这样的:
我创建了目录/etc/apache2/extra/vhosts/
。
我创建了一个/etc/apache2/extra/vhosts/localhost.conf
:
ServerName localhost
DocumentRoot "/www/localhost"
<Directory /www/localhost>
Require all granted
</Directory>
ErrorLog "/var/log/apache2/localhost.error_log"
CustomLog "/var/log/apache2/localhost.access_log" common
答/etc/apache2/extra/vhosts/foo.conf
:
ServerName foo.com
DocumentRoot "/www/foo.com"
<Directory /www/foo.com>
Require all granted
</Directory>
ErrorLog "/var/log/apache2/foo.com.error_log"
CustomLog "/var/log/apache2/foo.com.access_log" common
答/etc/apache2/extra/vhosts/bar.conf
:
ServerName bar.com
DocumentRoot "/www/bar.com"
<Directory /www/bar.com>
Require all granted
</Directory>
ErrorLog "/var/log/apache2/bar.com.error_log"
CustomLog "/var/log/apache2/bar.com.access_log" common
最后一个/etc/apache2/extra/vhosts/ssl.conf
:
SSLEngine on
SSLCertificateFile "/etc/apache2/ssl/server.crt"
SSLCertificateKeyFile "/etc/apache2/ssl/server.key"
在我的/etc/apache2/extra/httpd-vhosts.conf
:
<VirtualHost *:80>
Include /etc/apache2/extra/vhosts/localhost.conf
</VirtualHost>
<VirtualHost *:443>
Include /etc/apache2/extra/vhosts/localhost.conf
Include /etc/apache2/extra/vhosts/ssl.conf
</VirtualHost>
<VirtualHost *:80>
Include /etc/apache2/extra/vhosts/foo.conf
</VirtualHost>
<VirtualHost *:443>
Include /etc/apache2/extra/vhosts/foo.conf
Include /etc/apache2/extra/vhosts/ssl.conf
</VirtualHost>
<VirtualHost *:80>
Include /etc/apache2/extra/vhosts/bar.conf
</VirtualHost>
<VirtualHost *:443>
Include /etc/apache2/extra/vhosts/bar.conf
Include /etc/apache2/extra/vhosts/ssl.conf
</VirtualHost>