Apache中的dynamic身份validation领域

我有一台前端服务器充当许多(一个dynamic的“多”)楼宇监视器的网关代理与embedded式Web服务器。

他们可以通过以下URL访问:

http://www.example.com/monitor1/ http://www.example.com/monitor2/ ... 

我试图限制对这些监视器的访问权限,只有拥有它们的用户。 所以我需要的是一种为特定目录的用户或组指定权限的方法。

我在Apache中看到的标准authentication机制将不起作用,因为我需要指定每个位置。 我更喜欢一些dynamic地图或脚本。

有什么build议么?

好的,这是一个快速和非常好的方式来做到这一点。 简短的故事是,我没有办法(我知道)dynamic地做你所要求的标准Apache工具。 额外的模块或代码是必要的。 那里有人可能已经做出了你想要的模块。 我没有去看。

在你的Apacheconfiguration文件中安装并启用mod_perl,然后将这个块放到你的configuration文件中,在LoadModule for perl之后。 它不必在任何虚拟主机或目录或类似的东西。

 <Perl> use Apache2::ServerUtil qw//; use Apache2::RequestRec qw//; use Apache2::RequestUtil qw//; use Apache2::Const qw/OK DECLINED/; my $s = Apache2::ServerUtil->server; $s->push_handlers(PerlHeaderParserHandler => sub { my($r) = @_; if ( $r->hostname eq 'www.example.com' && $r->uri =~ m|^/(monitor\d+)/$| ) { my $monitorDirectory = $1; eval{$r->add_config([ "AuthType basic", "AuthName 'secret $monitorDirectory'", "AuthUserFile /path/to/user/file", "require user $monitorDirectory" ])}; if ( $@ ) { warn $@ } return OK; } else { return DECLINED; } }); </Perl> 

基本上这是做的是看每个请求的URL,如果它匹配,在请求的authentication和授权阶段之前dynamic地插入一些configuration规则。 要修改它,请更改www.example.com位,正则expression式匹配^/(monitor\d+)/$以及要插入的指令列表。

这将留下一个用户文件来维护,其中用户名是来自url的目录名称。 如果每个目录需要多个用户,则必须使用组并维护该文件。 为此,更改require user $monitorDirectory require group $monitorDirectory并添加AuthGroupFile /path/to/group/file