【发布时间】:2014-06-15 19:09:49
【问题描述】:
我的 /home/user/projects 文件夹中有各种网站,我希望能够使用 Apache2 在浏览器上测试它们(它们有 PHP 文件和连接到数据库)。
我不想每次更改某些内容时都将它们复制到 var/www。我只想在浏览器中打开一个 URL,其余的应该由 Apache 完成。通过编辑主机文件来分配假域也很好,但我不知道如何实现它。我试过这个solution,但我无法访问这些文件。
更新 这是我到目前为止所做的:
首先,我配置了 hosts 文件。我使用
sudo打开etc/hosts 文件并添加以下行:127.0.0.2 projects。现在我应该可以从浏览器访问http://projects-
其次,Apache 虚拟目录。在 etc/apache2/sites-available 文件夹中,我创建了一个名为 projects 的新文件并添加以下代码(在 /home/user/projects 中,我有一个 index.html文件):
<VirtualHost *:80> ServerName com DocumentRoot /home/user/projects </VirtualHost>我保存并执行
sudo a2ensite projects,以激活主机。符号链接已在/etc/apache2/sites-enabled中创建 -
测试,在使用
sudo service apache2 restart重新启动 Apache 之后。我只收到两次警告:Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName现在我在浏览器中输入
http://projects,但显示403 Forbidden error (You don't have permission to access / on this server)。我用sudo chmod -R 755 /home/user/projects更改了/home/user/projects的权限,它是可执行的,但结果相同。
【问题讨论】:
标签: linux apache virtualhost http-status-code-403