Apache 2访问本地主机时出现问题


Apache 2 problems accessing localhost

这是我在这里的第一篇文章,我希望我的方法是正确的。

我在我的ubuntu 14.04本地机器上安装了apache2用于学习,我所有的文件都在我的home public_html文件夹中。

当我尝试访问一个网站,如localhost/~{user}/test/index.php一切工作正常,但当我试图访问相同的网站与localhost/home/{user}/public_html/test/index.php我得到以下错误:

请求的URL/home/{user}/public_html/test/index.php在此服务器上找不到。

Apache/2.4.7 (Ubuntu) Server at localhost Port 80

我尝试使用:

$echo dirname(__FILE__);

但是它返回/home/{user}/public_html/test.

那么为什么我不能用两个路径访问同一个文件呢?

让我们考虑第二个URL:

http://localhost**/home/user/test/index.php**

如果你查看Apache的配置,你会注意到有一个名为"DocumentRoot"的指令。该指令指定apache将URL中的初始"/"映射到哪里。

那么,假设DocumentRoot被设置为/var/www/htdocs当您请求路径/home/user/test/index.php时,它实际上会查找..../var/www/htdocs/home/user/test/index.php,我假设它不存在。看到DocumentRoot

好,那么为什么第一个有效呢?因为Apache的UserDir模块。这个小模块检查链接的"/~user/test/index.php"部分。波浪(~)是它的作用:)。然后它将/~user/映射到/home/user/,因此Apache将在/home/user/test/index.php中查找该文件瞧。

我有同样的问题。已启动Apache。我停止apache并启动nginx:

sudo service apache2 stop
sudo service nginx start