lighttpd:多个重写规则匹配时的奇怪行为

lighttpd:多个重写规则匹配时的奇怪行为

20-rewrite.conf的 php 应用程序如下所示:

$HTTP["host"] =~ "www.mydomain.com" {
    url.rewrite-once += (
        "^/(img|css)/.*" => "$0",
        ".*" => "/my_app.php"
    )
}

我希望能够在从 scm 更新应用程序时将 Web 服务器置于某种“维护”模式。为此,我的想法是在此文件之前启用一个额外的重写配置文件。该16-rewrite-maintenance.conf文件如下所示:

url.rewrite-once += (
    "^/(img|css)/.*" => "$0",
    ".*" => "/maintenance_app.php"
)

现在,在维护页面上,我有一个无法加载的徽标。我收到 404 错误。Lighttpd 调试显示以下内容:

2012-12-13 20:28:06: (response.c.300) -- splitting Request-URI 
2012-12-13 20:28:06: (response.c.301) Request-URI  :  /img/content/logo.png 
2012-12-13 20:28:06: (response.c.302) URI-scheme   :  http 
2012-12-13 20:28:06: (response.c.303) URI-authority:  localhost 
2012-12-13 20:28:06: (response.c.304) URI-path     :  /img/content/logo.png 
2012-12-13 20:28:06: (response.c.305) URI-query    :   
2012-12-13 20:28:06: (response.c.300) -- splitting Request-URI 
2012-12-13 20:28:06: (response.c.301) Request-URI  :  /img/content/logo.png, /img/content/logo.png 
2012-12-13 20:28:06: (response.c.302) URI-scheme   :  http 
2012-12-13 20:28:06: (response.c.303) URI-authority:  localhost 
2012-12-13 20:28:06: (response.c.304) URI-path     :  /img/content/logo.png, /img/content/logo.png 
2012-12-13 20:28:06: (response.c.305) URI-query    :   
2012-12-13 20:28:06: (response.c.349) -- sanatising URI 
2012-12-13 20:28:06: (response.c.350) URI-path     :  /img/content/logo.png, /img/content/logo.png 
2012-12-13 20:28:06: (mod_access.c.135) -- mod_access_uri_handler called 
2012-12-13 20:28:06: (response.c.470) -- before doc_root 
2012-12-13 20:28:06: (response.c.471) Doc-Root     : /www
2012-12-13 20:28:06: (response.c.472) Rel-Path     : /img/content/logo.png, /img/content/logo.png 
2012-12-13 20:28:06: (response.c.473) Path         :  
2012-12-13 20:28:06: (response.c.521) -- after doc_root 
2012-12-13 20:28:06: (response.c.522) Doc-Root     : /www 
2012-12-13 20:28:06: (response.c.523) Rel-Path     : /img/content/logo.png, /img/content/logo.png 
2012-12-13 20:28:06: (response.c.524) Path         : /www/img/content/logo.png, /img/content/logo.png 
2012-12-13 20:28:06: (response.c.541) -- logical -> physical 
2012-12-13 20:28:06: (response.c.542) Doc-Root     : /www
2012-12-13 20:28:06: (response.c.543) Rel-Path     : /img/content/logo.png, /img/content/logo.png 
2012-12-13 20:28:06: (response.c.544) Path         : /www/img/content/logo.png, /img/content/logo.png 
2012-12-13 20:28:06: (response.c.561) -- handling physical path 
2012-12-13 20:28:06: (response.c.562) Path         : /www/img/content/logo.png, /img/content/logo.png 
2012-12-13 20:28:06: (response.c.618) -- file not found 
2012-12-13 20:28:06: (response.c.619) Path         : /www/img/content/logo.png, /img/content/logo.png 

有没有线索可以解释为什么 lighttpd 匹配这两条规则(来自我的应用程序重写配置和我的维护重写配置)并用逗号连接它们 - 这似乎没有任何意义?!它不应该在第一次匹配重写一次后停止吗?

答案1

url.rewrite是一个关联数组(哈希、字典等)。“添加”另一个具有重复键的数组意味着值将用逗号连接起来(就像合并重复的 http 标头一样)。

lighttpd -p -f /etc/lighttpd/lighttpd.conf

是了解 lighttpd 如何看待你的配置的好方法。

编辑

为了启用维护规则,我将在结尾配置(最后一个活动块获胜)

$HTTP["host"] =~ "www.mydomain.com" {
    url.rewrite-once = (
        "^/(img|css)/.*" => "$0",
        ".*" => "/maintenance_app.php"
    )
}

相关内容