duanfeng3879 2014-05-10 17:13
浏览 90
已采纳

访问localhost的Apache 2问题

This is my first post here and I hope I'm doing the right way.

I installed apache2 in my ubuntu 14.04 local machine for studying purposes and all my files are in my home public_html folder.

When I try to access a site like localhost/~{user}/test/index.php everything works fine, but when I try to access the same site with localhost/home/{user}/public_html/test/index.php I get the following error:

The requested URL /home/{user}/public_html/test/index.php was not found on this server.

Apache/2.4.7 (Ubuntu) Server at localhost Port 80

I tried to use:

$echo dirname(__FILE__);

But it returns /home/{user}/public_html/test.

So why can't I access the same file with both paths?

  • 写回答

1条回答 默认 最新

  • dqfwcj0030 2014-05-10 18:11
    关注

    Lets' consider the second URL:

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

    If you look in Apache's configuration you will notice that there is a directive called "DocumentRoot". This directive specifies where apache will map the initial "/" in the URL to.

    So, let's say that the DocumentRoot is set to /var/www/htdocs. When you request the path /home/user/test/index.php it will actially go looking for .... /var/www/htdocs/home/user/test/index.php, which I'm assuming doesn't exist. See DocumentRoot

    Ok, so why does the first one work? Because of Apache's UserDir module. This little module checks the "/~user/test/index.php" part of the link. The tilde (~) is what does it :). It then maps /~user/ to /home/user/, thus Apache will look for the file at /home/user/test/index.php. Voilá.

    Hope this helps.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
  • ¥15 再不同版本的系统上,TCP传输速度不一致
  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程