2

在阅读了各种教程 [1] 之后,我仍然无法让我的 VirtualHost 设置按预期工作。当我403 Forbidden尝试将 VirtualHost 与我的用户目录下的目录用作其DocumentRoot.

到目前为止我所做的

  • 创建的文件/etc/apache2/sites-available/workspace具有以下内容:

    NameVirtualHost *:80
    <VirtualHost *:80>
        ServerName project-site
        DocumentRoot /home/user/Workspace/project/site
    </VirtualHost>
    
  • 编辑后的文件/etc/hosts现在产生:

    127.0.0.1   localhost
    127.0.1.1   my-machine
    
    # The following lines are desirable for IPv6 capable hosts
    ::1     ip6-localhost ip6-loopback
    fe00::0 ip6-localnet
    ff00::0 ip6-mcastprefix
    ff02::1 ip6-allnodes
    ff02::2 ip6-allrouters
    
    # VirtualHosts added by me
    127.0.0.1   project-site
    
  • 启用虚拟主机使用sudo a2ensite workspace

  • 使用重新启动 Apachesudo services apache2 restart
  • 尝试在我的网络浏览器中打开http://project-sitehttp://project-site/test.html(在哪里test.html存在)/home/user/Workspace/project/site/

发生什么了

  • 重新启动 Apache 我在命令行上收到以下消息:

    * Restarting web server apache2
    apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
    [Sun May 13 10:33:37 2012] [warn] NameVirtualHost *:80 has no VirtualHosts
    [ OK ]
    
  • 打开http://project-sitehttp://project-site/test.html提供“403 Forbidden”。

应该发生什么

/home/user/Workspace/project/site当我浏览到http://project-site.

到目前为止我学到了什么

通过阅读此站点上的类似问题,我了解到这可能是权限问题 [2]。中的文件/home/user/Workspace/project/site可能无法被www-data. 但我怎么知道或纠正这一点?

此外.htaccess,文件被提到 [3] 位于

/home/.htaccess
/home/user/.htacces
[...]
/home/user/path/to/project/.htaccess

并且可能不可读。我从未创造过它们,我不想要它们,我会需要它们吗?

另一个问题 [4] 的第二个答案让我NameVirtualHost负责 Apache 重启时的警告。是否有必要,如果,我该如何正确使用它?

任何帮助深表感谢!告诉我,如果您需要知道任何其他信息来定位问题。


资源

  1. http://www.thegeekstuff.com/2011/07/apache-virtual-host/, http://httpd.apache.org/docs/2.2/vhosts/name-based.html, http://mintarticles.com/read/software-articles/multiple-virtual-hosts-in-xampplampp-in-ubuntu,977/, http://www.pgorecki.pl/content/virtual-host-na-localho%C5%9Bcie-apache-ubuntu, ...
  2. Apache VirtualHost 403 被禁止
  3. Ubuntu、Apache、虚拟主机和访问被禁止
  4. 虚拟主机配置
4

1 回答 1

1

我找到了以下解决方案,不满足我,但解决了我的主要问题。实际上,它与 [1] 中建议的权限有关。/home/user网络服务器无法访问我的目录。为了授予我使用的最小权限

chmod 701 /home/user

使其可访问。此外,我递归地为虚拟主机的 webroot 授予组所有权,www-data如 [2] 中推荐的那样,但我不确定这是否有必要。

sudo chown -R user:www-data /home/user/Workspace/project/site
sudo chmod -R g+s /home/user/Workspace/project/site

我将在一个单独的问题中要求一个更优雅的解决方案。

关于提到的其他问题,除了其他资源之外,我在 [3] 的帮助下发现了以下内容:

  • NameVirtualHost *:80如果它出现在 apache 的其他配置文件之一中,则没有必要并且可能会导致虚拟主机描述中出现错误。
  • 为了让 apache 知道它的完全限定域名是localhostone,创建了一个/etc/apache2/conf.d/fqdn包含 content的文件ServerName localhost

  1. https://stackoverflow.com/a/7576526/948404
  2. https://stackoverflow.com/a/9133067/948404
  3. https://help.ubuntu.com/community/ApacheMySQLPHP
于 2012-05-17T17:54:06.467 回答