【发布时间】:2012-05-21 05:12:15
【问题描述】:
阅读各种教程 [1] 后,我仍然无法让我的 VirtualHost 设置按预期工作。当我尝试将 VirtualHost 与我的用户目录下的目录用作其DocumentRoot 时,我得到了403 Forbidden。
到目前为止我做了什么
-
创建文件
/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启用虚拟主机- 使用
sudo services apache2 restart重新启动 Apache - 尝试在我的网络浏览器中打开
http://project-site和http://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-site或http://project-site/test.html会提供“403 Forbidden”。
应该发生什么
当我浏览到 http://project-site 时,我希望提供 /home/user/Workspace/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 重启时的警告。是否有必要,如果,如何正确使用?
非常感谢任何帮助!告诉我,如果您需要知道任何其他信息来定位问题。
资源
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, ...- Apache VirtualHost 403 Forbidden
- Ubuntu, Apache, virtualhost and Access forbidden
- VirtualHost configuration
【问题讨论】:
-
+1 你的问题解决了我的问题 :)
标签: apache ubuntu apache2 virtualhost