每个用户目录的 Apache RewriteRule

每个用户目录的 Apache RewriteRule

我的每个用户主文件夹中都有两个目录:.html-data.cgi-bin。第一个目录包含静态(.html)文件,第二个目录包含用于动态文档生成的文件。

每个用户都应该能够发布.html-data上的文件夹内容和上的文件夹http://myhost.com/~<username>/内容。动态内容创建的脚本应该是.cgi-binhttp://myhost.com/~<username>/cgi-bin/以提供它们的用户身份执行(例如,~steve/cgi-bin/test.cgi应以用户 steve 的身份执行)。

为此,我为 Apache 2.4 的 userdir 模块配置了以下配置:

UserDir .html-data
UserDir disabled root

<Directory "/home/*/.html-data">
    RewriteEngine On
    RewriteBase /~username/
    RewriteRule "^/cgi-bin/(.*)" "../../.cgi-bin/$1"
    AllowOverride FileInfo AuthConfig Limit Indexes
    Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
    Require method GET POST OPTIONS
</Directory>

<Directory "/home/*/.cgi-bin">
    Options ExecCGI
    SetHandler cgi-script
    Satisfy any
</Directory>

但是,这不起作用。RewriteRule 似乎错误。我怎样才能引用用户.cgi-bin目录?

这是错误日志:

[Thu Aug 04 20:14:17 2016] [trace3] mod_rewrite.c(477): [client 10.0.2.2:44058] 10.0.2.2 - - [myhost.com/sid#19f4a48][rid#1a639b0/initial] [perdir /home/*/.html-data/] add path info postfix: /home/steve/.html-data/cgi-bin -> /home/steve/.html-data/cgi-bin/hello.cgi
[Thu Aug 04 20:14:17 2016] [trace3] mod_rewrite.c(477): [client 10.0.2.2:44058] 10.0.2.2 - - [myhost.com/sid#19f4a48][rid#1a639b0/initial] [perdir /home/*/.html-data/] applying pattern '^/cgi-bin/(.*)' to uri '/home/steve/.html-data/cgi-bin/hello.cgi'
[Thu Aug 04 20:14:17 2016] [trace1] mod_rewrite.c(477): [client 10.0.2.2:44058] 10.0.2.2 - - [myhost.com/sid#19f4a48][rid#1a639b0/initial] [perdir /home/*/.html-data/] pass through /home/steve/.html-data/cgi-bin

答案1

我解决了。我正在使用mpm_itk现在。结合重写规则,可以定义执行脚本的用户:

RewriteEngine on
RewriteRule "^.*" - [E=ITKUID:http]
RewriteRule "^/~root.*" - [L,R=404]
RewriteRule "^/~([a-z]+)/cgi-bin(.*)" "/home/$1/.cgi-bin$2" [L,E=ITKUID:$1]
RewriteRule "^/~([a-z]+)/?(.*)" "/home/$1/.html-data/$2" [L,E=ITKUID:http]
AssignUserIDExpr %{reqenv:ITKUID}

相关内容