Apache HTTP 服务器 2.2 文档--从 URL 映射到文件系统(部分翻译)

Mapping URLs to Filesystem Locations

从 URL 映射到文件系统

DocumentRoot

文档根目录

In deciding what file to serve for a given request, Apache's default behavior is to take 

the URL-Path for the request (the part of the URL following the hostname and port) and add it to the end of the DocumentRoot specified in your configuration files. 

在决定用什么文件响应一个已经到达的请求时,Apache的默认行为是用url路径来响应请求(这一部分的url地址是跟随在主机名和端口号之后的),并且将它添加到在你的配置文件中确定的文档根目录的结尾。

Therefore, the files and directories underneath the DocumentRoot make up the basic document tree which will be visible from the web.

因此,在根目录下的文件和目录将会使服务器的目录结构对于互联网变得可见。

For example, if DocumentRoot were set to /var/www/html then a request for http://www.example.com/fish/guppies.html would result in the file /var/www/html/fish/guppies.html being served to the requesting client.

例如,如果根目录被设置为/var/www/html,之后一个http://www.example.com/fish/guppies.html的网页请求将使文件/var/www/html/fish/guppies.html被送达给请求客户端。

Apache is also capable of Virtual Hosting, where the server receives requests for more than one host. 

Apache也可能是虚拟的主机,此时服务器为超过一个主机接收服务请求。

In this case, a different DocumentRoot can be specified for each virtual host, or alternatively, the directives provided by the module mod_vhost_alias can be used to dynamically determine the appropriate place from which to serve content based on the requested IP address or hostname.

在这种情况,可以为每一个不同的虚拟主机设置不同的根目录,或者采用另一种方法,由模块mod_vhost_alias提供的命令可以用于动态确定服务内容(基于ip地址或者主机名请求)所在的位置。

The DocumentRoot directive is set in your main server configuration file (httpd.conf) and, possibly, once per additional Virtual Host you create.

每当你新建一个额外的虚拟主机的时候,文档根目录指令将会在你的主服务器配置文件(httpd.conf) 里被设置。

Files Outside the DocumentRoot

在文档根目录之外的文件

There are frequently circumstances where it is necessary to allow web access to parts of the filesystem that are not strictly underneath the DocumentRoot. 

经常有一些情况,有必要允许网页连接到一些不严格位于根目录之下的文件系统。

Apache offers several different ways to accomplish this. 

Apache 提供了几种完成这种工作的方法。

On Unix systems, symbolic links can bring other parts of the filesystem under the DocumentRoot. 

在unix系统中,符号链接可以使其他部分的文件系统位于文档根目录之下。

For security reasons, Apache will follow symbolic links only if the Options setting for the relevant directory includes FollowSymLinks or SymLinksIfOwnerMatch.

出于安全的原因,Apache只有在相关目录FollowSymLinks或者SymLinksIfOwnerMatch被设置的情况下,才会使符号链接有效。

Alternatively, the Alias directive will map any part of the filesystem into the web space. For example, with 

Alias /docs /var/web

the URL http://www.example.com/docs/dir/file.html will be served from /var/web/dir/file.html.

另一种方法,把Alias目录被映射到其他部分的文件系统。例如,

Alias   /docs /var/web

url地址为http://www.example.com/docs/dir/file.html 的页面请求将用/var/web/dir/file.html页面来响应请求。

 The ScriptAlias directive works the same way, with the additional effect that all content located at the target path is treated as CGI scripts.

Alias脚本命令以同样的方式运行。使用附加的效果:所有位于目标路径的内容被当作CGI脚本

For situations where you require additional flexibility, you can use the AliasMatch and ScriptAliasMatch directives to do powerful regular expression based matching and substitution. For example,

在你需要更灵活的情况下,AliasMatch 和 ScriptAliasMatch命令可以让你使用基于匹配和替换的正则表达式。例如,

ScriptAliasMatch ^/~([a-zA-Z0-9]+)/cgi-bin/(.+) /home/$1/cgi-bin/$2

will map a request to http://example.com/~user/cgi-bin/script.cgi to the path /home/user/cgi-bin/script.cgi and will treat the resulting file as a CGI script.

将会映射http://example.com/~user/cgi-bin/script.cgi的页面请求为/home/user/cgi-bin/script.cgi,并且将最后的文件视为一个CGI 脚本。

User Directories

用户目录

Traditionally on Unix systems, the home directory of a particular user can be referred to as ~user/. The module mod_userdir extends this idea to the web by allowing files under each user's home directory to be accessed using URLs such as the following.

一般来说,在unix系统上,一个用户的主目录可以以~user/来引用。模块mod_userdir 拓展这个思想到了网络,它允许通过url地址来访问位于用户主目录下的文件。如下:

http://www.example.com/~user/file.html

For security reasons, it is inappropriate to give direct access to a user's home directory from the web. Therefore, the UserDir directive specifies a directory underneath the user's home directory where web files are located. Using the default setting of Userdir public_html, the above URL maps to a file at a directory like

/home/user/public_html/file.html where /home/user/ is the user's home directory as specified in /etc/passwd.

出于安全方面的考虑,从网络上直接可以访问用户主目录是不合适的。因此,UserDir命令指定一个位于用户主目录之下的目录用于存放网页文件。使用默认的Userdir public_html设置,上述的url将被映射到某个文件夹下某个的文件,例如:

/home/user/public_html/file.html 。/home/user/是用户的主目录,在/etc/passwd.中被指定。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值