【问题标题】:Why doesn't this Apache virtualhost entry work?为什么这个 Apache 虚拟主机条目不起作用?
【发布时间】:2014-03-11 07:16:45
【问题描述】:

我在 Ubuntu 13 上运行 Apache 2.4.6。

在可用的站点中,我的站点有一个 conf 文件,其中仅包含以下内容:

<VirtualHost *:80>
  # Admin email, Server Name (domain name), and any aliases
  ServerAdmin somebody@somewhere.com
  ServerName  www.ourco.me
  ServerAlias ourco.me

  # Index file and Document Root (where the public files are located)
  DirectoryIndex index.html index.php
  DocumentRoot /home/ouruser/public/ourco.me/public

  # Log file locations
  LogLevel warn
  ErrorLog  /home/ouruser/public/ourco.me/log/error.log
  CustomLog /home/ouruser/public/ourco.me/log/access.log combined
</VirtualHost>

没有启用其他配置文件。当我使用 apachectl -S 显示网站时,它显示:

VirtualHost configuration:
*:80                   is a NameVirtualHost
         default server www.ourco.me (/etc/apache2/sites-enabled/ourco.me.conf:1)
         port 80 namevhost www.ourco.me (/etc/apache2/sites-enabled/ourco.me.conf:1)
                 alias ourco.me
         port 80 namevhost www.ourco.me (/etc/apache2/sites-enabled/ourco.me.conf:1)
                 alias ourco.me
ServerRoot: "/etc/apache2"
Main DocumentRoot: "/var/www"
Main ErrorLog: "/var/log/apache2/error.log"
Mutex watchdog-callback: using_defaults
Mutex default: dir="/var/lock/apache2" mechanism=fcntl 
Mutex mpm-accept: using_defaults
PidFile: "/var/run/apache2/apache2.pid"
Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG
User: name="www-data" id=33
Group: name="www-data" id=33

我注意到的第一件事是 namevhost www.ourco.me 的重复条目。当我在浏览器中访问该网站时,我得到:

您无权访问此服务器上的 /。

Apache/2.4.6 (Ubuntu) 服务器位于 www.ourco.me 端口 80

conf文件中指定的所有目录和文件都存在。 a2ensite 和 a2dissite 按预期工作,从启用了站点的文件中添加/删除此文件的符号链接,因此它正在查看正确的文件。有谁知道为什么它的指令被忽略?谢谢。

【问题讨论】:

    标签: apache virtualhost


    【解决方案1】:
    Put Allow from all
    
    <VirtualHost *:80>
      # Admin email, Server Name (domain name), and any aliases
      ServerAdmin somebody@somewhere.com
      ServerName  www.ourco.me
      ServerAlias ourco.me
    
      # Index file and Document Root (where the public files are located)
      DirectoryIndex index.html index.php
      DocumentRoot /home/ouruser/public/ourco.me/public
    
      # Log file locations
      LogLevel warn
      ErrorLog  /home/ouruser/public/ourco.me/log/error.log
      CustomLog /home/ouruser/public/ourco.me/log/access.log combined
     Allow from all
    </VirtualHost>
    

    【讨论】:

    • 谢谢,但这不起作用。结果是:AH00526:/etc/apache2/sites-enabled/ourco.me.conf 第 16 行的语法错误:此处不允许操作“configtest”失败。
    • “要求所有授权”,这似乎是新语法,也失败并显示类似消息。
    【解决方案2】:

    这似乎解决了问题:

    <Directory />
      Require all granted
    </Directory>
    

    当放置在 VirtualHost 条目中时。

    那个 sn-p 来自this post。我正在查看 this Apache doc 以了解它为什么有效。

    【讨论】:

      猜你喜欢
      • 2018-05-09
      • 2015-02-08
      • 2022-01-12
      • 2015-10-23
      • 1970-01-01
      • 2015-03-05
      • 2015-02-22
      • 2013-08-29
      相关资源
      最近更新 更多