Apache-2.4
每個使用者目錄的 Apache RewriteRule
我的每個使用者的主文件夾中有兩個目錄:
.html-data
和.cgi-bin
. 第一個包含靜態 (.html) 文件,第二個包含用於動態文件生成的文件。每個使用者都應該能夠在 上發布
.html-data
文件夾的內容以及在 上發布文件夾http://myhost.com/~<username>/
的內容。用於動態內容創建的腳本應該作為提供它們的使用者來執行(例如應該作為使用者 steve 來執行)。.cgi-bin``http://myhost.com/~<username>/cgi-bin/``~steve/cgi-bin/test.cgi
為此,我為 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
我解決了。我現在正在使用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}