Chinaunix首页 | 论坛 | 博客
  • 博客访问: 17758096
  • 博文数量: 7460
  • 博客积分: 10434
  • 博客等级: 上将
  • 技术积分: 78178
  • 用 户 组: 普通用户
  • 注册时间: 2008-03-02 22:54
文章分类

全部博文(7460)

文章存档

2011年(1)

2009年(669)

2008年(6790)

分类:

2008-04-18 09:29:55

一.基本的用户认证:

若对某一目录下的文件如/home/ftp/pub需要做到用户认证,则在httpd.conf中加入下面的行
<>
options indexes followsymlinks
allowoverride authconfig
order allow,deny
allow from all

<>
用在目录/home/ftp/pub下放文件.htaccess,内容如下:
authname "shared files"
authtype basic
authuserfile /etc/.passwd
require valid-user

用随apache来的程序htpasswd 生成文件/etc/.passwd,每行一个用户名:密码

只要能提供正确的用户名和密码对,就允许登录访问,这是针对任何地址来的请求都要求提供用户名和密码认证。

二.针对部分网段或地址要求认证。

若公司lan所在网段为192.168.0.0/24,且有一防火墙专线接入internet,内部网卡的地址为192.168.0.1/32,则现在希望所有通过拨本地163通过防火墙上的apache反向代理向lan上的另一www服务器访问时需要认证,而本地lan上的用户不需认证。可以在httpd.conf中放入:
〈directory /home/ftp/pub>
options indexes followsymlinks
allowoverride authconfig
order deny,allow
deny from 192.168.0.1
〈/directory>

且在/home/ftp/pub/.htaccess中放入:
authname "shared files"
authtype basic
authuserfile /etc/.passwd
require valid-user
satisfy any

三.对同一目录及其下的子目录有不同的权限,仅某些人可以存取一目录下的子目录。
如有一目录/home/ftp/pub/sales,有三个用户user1,user2,user3都需要用户名和密码进入/home/ftp/pub,但仅user1,user2能进入/home/ftp/pub/sales.则放下面的行到httpd.conf

〈directory /home/ftp/pub>
options indexes
allowoverride authconfig
order allow,deny
allow from all
〈/directory>

〈directory /home/ftp/pub/sales>
options indexes
allowoverride authconfig
order allow,deny
allow from all
〈/directory>

且看/home/ftp/pub/.htaccess为:
authname "shared files"
authtype basic
authuserfile /etc/.passwd
require valid-user

且看/home/ftp/pub/sales/.htaccess
authname "shared files"
authtype basic
authuserfile /etc/.passwd
authgroupfile /etc/.salesgroup
require group manager

且文件/etc/.passwd内容为:
user1:passwd1
user2:passwd2
user3:passwd3

且文件/etc/.salesgroup内容为:
manager: user1 user2

阅读(692) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~