为同一个 VirtualHosts 声明多个端口:
SSLStrictSNIVHostCheck off
# Apache setup which will listen for and accept SSL connections on port 443.
Listen 443
# Listen for virtual host requests on all IP addresses
NameVirtualHost *:443
<VirtualHost *:443>
ServerName domain.localhost
DocumentRoot "/Users/<my_user_name>/Sites/domain/public"
<Directory "/Users/<my_user_name>/Sites/domain/public">
Order allow,deny
Allow from all
</Directory>
# SSL Configuration
SSLEngine on
...
</VirtualHost>
如何为“domain.localhost”声明一个新端口(“listen”,ServerName,...)?
如果我添加以下代码,apache 也会对“domain.localhost”的所有其他子域(subdomain1.domain.localhost、subdomain2.domain.localhost,...)起作用(太多了):
<VirtualHost *:80>
ServerName pjtmain.localhost:80
DocumentRoot "/Users/Toto85/Sites/pjtmain/public"
RackEnv development
<Directory "/Users/Toto85/Sites/pjtmain/public">
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
答案1
这个问题有点模糊,但我会尽力提供帮助。
如果您希望同一个虚拟主机监听多个端口,那么您可以这样做:
Listen 80
NameVirtualHost *:80
Listen 8080
NameVirtualHost *:8080
<VirtualHost *:80 *:8080>
ServerName some.domain.name
ServerAlias some.other.domain.name
....
</VirtualHost>
一般来说,您不会定义同一域名的多个基于名称的 VirtualHosts,除非您需要使用不同的协议。
对于基于 SSL 名称的虚拟主机,您必须格外小心:根据定义,同一个 IP:端口上不能有多个证书,因此,为了避免证书错误,它必须是通配符证书,涵盖所有提供的域名。