【问题标题】:Apache/Lion not serving site on localhost with name based virtual hosting supportApache/Lion 不在本地主机上提供基于名称的虚拟主机支持的站点
【发布时间】:2011-12-26 22:09:54
【问题描述】:

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

【问题讨论】:

    标签: php apache localhost


    【解决方案1】:

    尝试将第一行更改为 NameVirtualHost *:80 而不是 NameVirtualHost *.:80。 此外,在 DocumentRoot "/Library/WebServer/Documents" 引号中为 _default_ 添加您的 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>
    

    【讨论】:

    • 仅当路径中有空格时才需要引号,以消除指令的多个参数的歧义。
    • 同意,我只是添加它以与文件的其余部分保持一致。
    • 我已经一一实现了上述所有更改,每次更改我的 ~/ Sites 文件夹,当我导航到 http://localhost/thewebsite.local 时,我仍然收到 404 File Not Found
    • 导航到http://thewebsite.local而不是http://localhost/thewebsite.local
    【解决方案2】:

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

    名称虚拟主机 *:80

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-09-08
      • 2011-05-13
      • 1970-01-01
      • 2013-12-13
      • 1970-01-01
      • 2016-04-24
      • 2018-06-26
      • 1970-01-01
      相关资源
      最近更新 更多