Apache / Lion不在localhost上提供基于名称的虚拟主机支持的站点

时间:2011-12-26 22:09:55

标签: php apache localhost

我已经为基于名称的虚拟主机配置了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

2 个答案:

答案 0 :(得分:0)

尝试将第一行更改为NameVirtualHost *:80而不是NameVirtualHost *.:80。 另外,在引号_default_中添加DocumentRoot "/Library/WebServer/Documents"的documentRoot(只是为了在整个文件中保持一致)。 还尝试在虚拟主机内添加目录权限。

我在下面的代码中进行了更改。试试吧。

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


# 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"
    <Directory "/Users/myusername/Sites">
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

答案 1 :(得分:0)

在httpd.conf文件的末尾添加以下行:

    NameVirtualHost *:80