查看完整版本: Apache简单实验1:用户个人主页、分布式授权,符号链接,别名,页面重定向

赵高 2008-1-13 18:53

Apache简单实验1:用户个人主页、分布式授权,符号链接,别名,页面重定向

试验环境:虚拟机
服务器:CentOS 5 IP:192.168.175.88

<零>,安装Apache
想不到最小安装的CentOS已经将Apache安装好了!那就先做个备份吧。

[attach]195361[/attach]

<一>,用户个人主页
找到
[code]#
# UserDir: The name of the directory that is appended onto a user's home
# directory if a ~user request is received.
#
# The path to the end user account 'public_html' directory must be
# accessible to the webserver userid.  This usually means that ~userid
# must have permissions of 711, ~userid/public_html must have permissions
# of 755, and documents contained therein must be world-readable.
# Otherwise, the client will only receive a "403 Forbidden" message.
#
# See also: http://httpd.apache.org/docs/misc/FAQ.html#forbidden
#
<IfModule mod_userdir.c>
    #
    # UserDir is disabled by default since it can confirm the presence
    # of a username on the system (depending on home directory
    # permissions).
    #
    UserDir disable
    #
    # To enable requests to /~user/ to serve the user's public_html
    # directory, remove the "UserDir disable" line above, and uncomment
    # the following line instead:
    #
    #UserDir public_html
</IfModule>[/code]
修改为
[code]<IfModule mod_userdir.c>
    UserDir disable root 不让root用户有自己的主页
    UserDir public_html  每个用户的主页在自己家目录里面的public_html里面
</IfModule>[/code]
用ccna30在家目录建立public_html目录并建立简单主页文件index.html
在客户端访问

[attach]195362[/attach]

明显是权限问题

我们看/home/ccna30文件夹的权限是700,也就是说,Apache想要进入的目录的other权限为0,自然进不去,改成711。访问成功。其实上面的注释里面早就说过了:This usually means that ~userid must have permissions of 711, ~userid/public_html must have permissions of 755...

赵高 2008-1-13 18:57

<二>,配置WebDAV

对于Web服务器来说,需要经常对其页面内容进行更新,因此这台服务器还需要FTP服务,这样会造成安全系数降低(真的吗?),所以用WebDAV(基于Web的分布式授权和版本控制)可以让用户无需FTP更新自己的网站,直接在浏览器里面上传下载啦。

[b]1,HTTP请求方法[/b]
根据HTTP标准,HTTP请求可以使用多种请求方法。例如:HTTP1.1支持7种请求方法:GET、POST、HEAD、OPTIONS、PUT、DELETE和TARCE。在Internet应用中,最常用的方法是GET和POST。为了安全,我们应该对用户可以拥有的请求方式(就是是否有上传下载的权限)进行授权。

比如我们让ccna30用户对根目录下面的webt目录有修改权利,其它用户只能看:应该配置为:
[code]AuthType Basic
AuthName DAV
AuthUserFile /etc/httpd/conf/user 认证用户密码验证文件
<LimitExcept GET OPTIONS>
Require user ccna30 用户ccna30可以修改网站
</Limit>[/code]

[b]2,配置服务端[/b]
例子目录为/var/www/html/webt,将以上代码放入httpd.conf配置部分
[code]<Directory "/var/www/html/webt">
    Options None
    Order allow,deny
    Allow from all
    Dav On
    AuthType Basic
    AuthName DAV
    AuthUserFile /etc/httpd/conf/user
    <LimitExcept GET OPTIONS>
     Require user ccna30
    </LimitExcept>
</Directory>[/code]

不要忘记密码验证文件
htpasswd -cm /etc/httpd/conf/user ccna30 为ccna30用户建立密码验证文件。

同时要将该目录权限赋予apache
chown -R apache:apache /var/www/html/webt

[b]3,客户端访问[/b]
Windows2000/XP安装后已经具备访问基于WebDAV协议的Web文件夹的功能,而且可以把Web文件夹映射为一个本地文件夹,支持拖放、拷贝/粘贴等等功能,使用起来非常方便。

在Windows2000/XP中添加Web文件夹的方法是:
打开“网上邻居”,添加网上邻居,在“请键入网上邻居的位置”中输入Web文件夹的地址,
然后按照向导的提示继续做就可以了,非常的简单。如下面两图所示:

[attach]195363[/attach]

[attach]195364[/attach]

看下图对比发现,HTTP还是不能访问(Options None),Web文件夹则可以进入目录

[attach]195365[/attach]

建立主页文件,直接拖拽过去之后可以访问了。

[attach]195366[/attach]

赵高 2008-1-13 18:58

<三>,符号链接
本功能可以使Apache主目录中的部分文件强制转移到其他目录或磁盘下。
默认情况下,httpd.conf中已经包含了符号链接的指令
[code]<Directory />
    Options FollowSymLinks
    ...
</Directory>
<Directory "/var/www/html">
    Options Indexes FollowSymLinks
    ...
</Directory>[/code]
我们用ln -s命令建立真实文件目录与根目录的链接即可。
[code]#格式 ln -s 真实目录 链接名称
ln -s /usr/share/girls girl[/code]
然后在客户端访问
[attach]195367[/attach]

赵高 2008-1-13 18:59

<四>,别名
这是另外一种将根目录文件以外的内容加入到站点中的方法,默认情况下,error目录和icons目录因为都在根目录以外,所以设置了这两个目录的别名访问,同时用Directory进行了权限设置。
我们将gg映射到/usr/share/girls中,同时设定权限。
[code]#格式 alias 别名 真实目录
Alias /gg "/usr/share/girls"
<Directory "/usr/share/girls">
Options Indexes
        Order allow,deny
Allow from all
</Directory>[/code]
然后在客户端访问

[attach]195368[/attach]

赵高 2008-1-13 18:59

<五>,页面重定向
配置格式为
Redirect [相应代码] 用户请求URL 重定向URL
示例
Redirect /1.jpg [url=http://192.168.175.88/2.jpg]http://192.168.175.88/2.jpg[/url]
注意:重定向URL必须是个完整的地址
客户端访问[url=http://192.168.175.88/1.jpg]http://192.168.175.88/1.jpg[/url]就会变成[url=http://192.168.175.88/2.jpg]http://192.168.175.88/2.jpg[/url]
[attach]195369[/attach]

rcgljxf 2008-1-15 23:15

学习了,谢谢赵大人。
赵大人,你的头象怎么显示不出来了。

[[i] 本帖最后由 rcgljxf 于 2008-1-15 23:16 编辑 [/i]]

周老师 2008-1-21 12:19

确实很简单。
页面重定向必须到完整的URL吗?

sharefish 2008-5-13 00:12

谢了

lc8421855 2008-5-15 21:04

很好的教学文章。。谢谢了
页: [1]
查看完整版本: Apache简单实验1:用户个人主页、分布式授权,符号链接,别名,页面重定向