我在 OSX 客户端上使用 VHosts 已经有一段时间了。最近,我一直试图使用http://localhost
它来访问,/Library/WebServer/Documents
但它总是将我重定向到我的博客。有人能告诉我我可能哪里出错了吗?
这是我的hosts
文件:
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
127.0.0.1 www.chrislrobinson.co.uk
127.0.0.1 blog.chrislrobinson.co.uk
这是我的httpd.conf
文件:
...
ServerName localhost:80
DocumentRoot "/Library/WebServer/Documents"
<Directory />
Options FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
</Directory>
<Directory "/Library/WebServer/Documents">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
Allow from all
</Directory>
最后这是我的httpd-vhosts.conf
<Directory /Library/WebServer/Documents>
Options Indexes FollowSymlinks MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>
<Directory /Library/WebServer/Documents/blog>
Options Indexes FollowSymlinks MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>
<Directory /Library/WebServer/Documents/chrislrobinson>
Options Indexes FollowSymlinks MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>
NameVirtualHost *:80
<VirtualHost 127.0.0.1>
DocumentRoot "/Library/WebServer/Documents"
ServerName localhost
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/Library/WebServer/Documents/blog"
ServerName blog.chrislrobinson.co.uk
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/Library/WebServer/Documents/chrislrobinson"
ServerName www.chrislrobinson.co.uk
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/Library/WebServer/Documents
ServerName www2.chrislrobinson.co.uk
</VirtualHost>
答案1
在 localhost 块上更改主机规范;它需要与NameVirtualHost
指令匹配。(当 apache 启动时,错误日志中应该会出现有关此问题的警告)
<VirtualHost *:80>
DocumentRoot "/Library/WebServer/Documents"
ServerName localhost
</VirtualHost>
由于将其放在默认端口监听器上可能会将其暴露给互联网(仅带有主机头localhost
,但仍然..),因此也考虑将其锁定:
Order deny,allow
Deny from all
Allow from 127.0.0.1