Apache/Lion 未在本地测试环境中提供网站服务

Apache/Lion 未在本地测试环境中提供网站服务

最初由超级用户发布...

我已经为基于名称的虚拟主机配置了 Apache,但似乎无法在浏览器中显示本地站点。我的 httpd.conf 配置错误了吗?以下是经过清理的版本:

#
# Use Name-based Virual Hosting.
#
NameVirtualHost *.:80

#
#Set up permissions for VirtualHosts in ~/Sites
#
<Directory "/Users/myusername/Sites">
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Order allow,deny
    Allow from all
</Directory>

# For http://localhost in the OSX default location
<VirtualHost _default_:80>
    ServerName localhost
    DocumentRoot /Library/WebServer/Documents
</VirtualHost>

<VirtualHost *:80>
    ServerName thewebsite.local
    CustomLog "/Users/myusername/Sites/logs/thewebsite.local-access_log" combined
    ErrorLog "/Users/myusername/Sites/logs/thewebsite.local-error_log"
    DocumentRoot "/Users/myusername/Sites/thewebsite.local"
</VirtualHost>

还有我的 etc/hosts

##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting.  Do not change this entry.
##
127.0.0.1       thewebsite.local
127.0.0.1       localhost
255.255.255.255 broadcasthost
::1             localhost
fe80::1%lo0     localhost

答案1

Apache 从上到下搜索虚拟主机列表,并将从与主机头匹配的第一个虚拟主机或默认虚拟主机(以先到者为准)传送内容。在您的配置中,默认虚拟主机列在最前面,因此其内容会被传送。将您的默认站点放在最后或至少放在您想要传送内容的站点之后。

NameVirtualHost指令通常是NameVirtualHost *:80。使用 .local 通常不是一个好主意,因为它会被 mDNS 等使用,并且可能会造成阻碍。

相关内容