apache如何使用或允许浏览/ usr / share? (linux / Ubuntu)

默认的apache.conf(ubuntu服务器)包含以下块:

# Sets the default security model of the Apache2 HTTPD server. It does # not allow access to the root filesystem outside of /usr/share and /var/www. # The former is used by web applications packaged in Debian, # the latter may be used for local directories served by the web server. If # your system is serving content from a sub-directory in /srv you must allow # access here, or in any related virtual host. # .... other items removed for brevity <Directory /usr/share> AllowOverride None Require all granted </Directory> 

我对这个指令的解释是,apache将允许web浏览/usr/share文件夹中的项目。 但如果我试图浏览和项目在/usr/share/我不能查看任何东西?

  1. 如何浏览/ usr / share中的内容?

    例如,如果我把浏览器指向localhost/synaptic/html/index.html我得到一个404找不到错误

  2. 如果apache允许浏览这个目录 – 我是否需要将其locking在生产服务器上?

  1. 您需要将URLpath映射到/ usr / share。 最简单的方法是使用Alias指令,例如:

     Alias /share /usr/share 

    然后http://localhost/share/synaptic将映射到/usr/share/synaptic 。 请参阅Alias的文档 。

  2. / usr / share中的所有文件对于非root用户已经不可写入,包括Apache用户www-data。 他们可能也都是世界可读的。 所以没有任何额外的限制,就可以按照上面的方式为所有人服务。 但是,如果/ usr / share中有公共文件,您不希望Apache用户看到,则可以使用Require all deny指令来阻止对这些文件的访问。