Apache用户认证方法汇总

资讯 驱动中国 rocket 3,191 次阅读 0 条评论
分享 Q

一.基本的Apache用户认证方法:

若对某一目录下的文件如/home/ftp/pub需要做到用户认证,则在httpd.conf
中加入下面的行
<>
optionsindexesfollowsymlinks
allowoverrideauthconfig
orderallow,deny
allowfromall

<>
用在目录/home/ftp/pub下放文件.htaccess,内容如下:
authname"sharedfiles"
authtypebasic
authuserfile/etc/.passwd
requirevalid-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>
OptionsIndexesFollowSymLinks
AllowOverrideAuthConfig
orderdeny,allow
denyfrom192.168.0.1
〈/Directory>

且在/home/ftp/pub/.htaccess中放入:
AuthName"sharedfiles"
AuthTypeBasic
AuthUserFile/etc/.passwd
requirevalid-user
satisfyany

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

〈Directory/home/ftp/pub>
OptionsIndexes
AllowOverrideAuthConfig
orderallow,deny
allowfromall
〈/Directory>

〈Directory/home/ftp/pub/sales>
OptionsIndexes
AllowOverrideAuthConfig
orderallow,deny
allowfromall
〈/Directory>

且看/home/ftp/pub/.htaccess为:
AuthName"sharedfiles"
AuthTypeBasic
AuthUserFile/etc/.passwd
requirevalid-user

且看/home/ftp/pub/sales/.htaccess
AuthName"sharedfiles"
AuthTypeBasic
AuthUserFile/etc/.passwd
AuthGroupFile/etc/.salesgroup
requiregroupmanager

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

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

汇总 方法 认证 用户 allow 目录 /etc/.pas
版权声明:本文由驱动中国整理发布,转载需注明出处与原文链接。如有疑问请联系 editor@qudong.com
本文价值 成为第一个评分的人
登录后为本文打分
网友评论0 条评论
正在回复 的评论取消
评论加载中…
🔐

登录后参与互动

评论、点赞均可赚积分
连续签到、邀请好友也有奖励 🎁

电脑端: 微信扫码登录 微信内: 一键登录

微信扫一扫

打开微信「扫一扫」,分享本文到朋友圈或好友