我在 apache 2.4.12 中定义了几个虚拟主机。它们都在监听端口 80,但名称不同。问题是我有 2 个略微相似的虚拟主机,当我尝试访问第二个虚拟主机时,第一个虚拟主机会被加载。这可能是什么问题?
escr.dev 主机
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName escr.dev
ServerAlias www.escr.dev
DocumentRoot /var/www/escr.dev/application/web/
<Directory /var/www/escr.dev/application/web/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ErrorLog /var/log/apache2/escr.dev-error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog /var/log/apache2/escr.dev-access.log combined
</VirtualHost>
esca.dev 主机
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName esca.dev
ServerAlias www.esca.dev
DocumentRoot /var/www/esca.dev/public/
<Directory /var/www/esca.dev/public/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ErrorLog /var/log/apache2/esca.dev-error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog /var/log/apache2/esca.dev-access.log combined
</VirtualHost>
因此,当我访问“esca.dev”时,我加载的是“escr.dev”主机。
答案1
您是否启用了“NameVirtualHost”指令?
您应该在 httpd.conf 中取消注释以下内容:
NameVirtualHost *:80
此指令需要与基于名称的虚拟主机一起工作。