lighttpd-IP地址的重定向

时间:2019-02-26 21:20:18

标签: redirect lighttpd http-redirect

我正在尝试将ipaddress-as-URL重定向为URL的正式主机名:

debug.log-request-handling = "enable" 
debug.log-request-header = "enable" 
debug.log-response-header = "enable" 
debug.log-ssl-noise = "enable" 
debug.log-condition-handling = "enable" 

$HTTP["host"] == "192.168.1.20" {
    url.redirect = ( ".*" => "http://pihole.home.lan/" )
}

但是它不起作用。相关日志条目:

2019-02-26 13:01:35: (request.c.436) fd: 10 request-len: 331 \nGET / HTTP/1.1\r\nHost: 192.168.1.20\r\nUser-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:65.0) Gecko/20100101 Firefox/65.0\r\nAccept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8\r\nAccept-Language: en-US,en;q=0.5\r\nAccept-Encoding: gzip, deflate\r\nConnection: keep-alive\r\nUpgrade-Insecure-Requests: 1\r\n\r\n 
2019-02-26 13:01:35: (response.c.261) run condition 
2019-02-26 13:01:35: (configfile-glue.c.694) === start of condition block === 
2019-02-26 13:01:35: (configfile-glue.c.557) SERVER["socket"] ( :80 ) compare to  [::]:80 
2019-02-26 13:01:35: (configfile-glue.c.615) 1 (uncached) result: false 
2019-02-26 13:01:35: (configfile-glue.c.694) === start of condition block === 
2019-02-26 13:01:35: (configfile-glue.c.557) HTTP["url"] ( / ) compare to  ^/admin/ 
2019-02-26 13:01:35: (configfile-glue.c.615) 2 (uncached) result: false 
2019-02-26 13:01:35: (configfile-glue.c.694) === start of condition block === 
2019-02-26 13:01:35: (configfile-glue.c.350) go parent global/HTTPurl=~^/admin/ 
2019-02-26 13:01:35: (configfile-glue.c.622) 2 (cached) result: false 
2019-02-26 13:01:35: (configfile-glue.c.615) 3 (uncached) result: skipped 
2019-02-26 13:01:35: (configfile-glue.c.694) === start of condition block === 
2019-02-26 13:01:35: (configfile-glue.c.557) HTTP["url"] ( / ) compare to  ^/admin/\.(.*) 
2019-02-26 13:01:35: (configfile-glue.c.615) 4 (uncached) result: false 
2019-02-26 13:01:35: (configfile-glue.c.694) === start of condition block === 
2019-02-26 13:01:35: (configfile-glue.c.557) HTTP["host"] ( 192.168.1.20 ) compare to  192.168.1.20 
2019-02-26 13:01:35: (configfile-glue.c.615) 5 (uncached) result: true 
2019-02-26 13:01:35: (configfile-glue.c.694) === start of condition block === 
2019-02-26 13:01:35: (configfile-glue.c.557) HTTP["host"] ( 192.168.1.20 ) compare to  pihole($|\.home\.lan) 
2019-02-26 13:01:35: (configfile-glue.c.615) 6 (uncached) result: false 
2019-02-26 13:01:35: (configfile-glue.c.694) === start of condition block === 
2019-02-26 13:01:35: (configfile-glue.c.350) go parent global/HTTPhost=~pihole($|\.home\.lan) 
2019-02-26 13:01:35: (configfile-glue.c.622) 6 (cached) result: false 
2019-02-26 13:01:35: (configfile-glue.c.615) 7 (uncached) result: skipped 
2019-02-26 13:01:35: (configfile-glue.c.694) === start of condition block === 
2019-02-26 13:01:35: (configfile-glue.c.350) go parent global/HTTPhost=~pihole($|\.home\.lan) 
2019-02-26 13:01:35: (configfile-glue.c.622) 6 (cached) result: false 
2019-02-26 13:01:35: (configfile-glue.c.615) 8 (uncached) result: skipped 
2019-02-26 13:01:35: (configfile-glue.c.694) === start of condition block === 
2019-02-26 13:01:35: (configfile-glue.c.350) go parent global/HTTPhost=~pihole($|\.home\.lan)/HTTPscheme==http 
2019-02-26 13:01:35: (configfile-glue.c.622) 8 (cached) result: skipped 
2019-02-26 13:01:35: (configfile-glue.c.615) 9 (uncached) result: skipped 
2019-02-26 13:01:35: (response.c.350) -- splitting Request-URI 
2019-02-26 13:01:35: (response.c.351) Request-URI     :  / 
2019-02-26 13:01:35: (response.c.352) URI-scheme      :  http 
2019-02-26 13:01:35: (response.c.353) URI-authority   :  192.168.1.20 
2019-02-26 13:01:35: (response.c.354) URI-path (raw)  :  / 
2019-02-26 13:01:35: (response.c.355) URI-path (clean):  / 
2019-02-26 13:01:35: (response.c.356) URI-query       :   
2019-02-26 13:01:35: (configfile-glue.c.694) === start of condition block === 
2019-02-26 13:01:35: (configfile-glue.c.622) 1 (cached) result: false 
2019-02-26 13:01:35: (configfile-glue.c.694) === start of condition block === 
2019-02-26 13:01:35: (configfile-glue.c.622) 2 (cached) result: false 
2019-02-26 13:01:35: (configfile-glue.c.694) === start of condition block === 
2019-02-26 13:01:35: (configfile-glue.c.622) 3 (cached) result: skipped 
2019-02-26 13:01:35: (configfile-glue.c.694) === start of condition block === 
2019-02-26 13:01:35: (configfile-glue.c.622) 4 (cached) result: false 
2019-02-26 13:01:35: (configfile-glue.c.694) === start of condition block === 
2019-02-26 13:01:35: (configfile-glue.c.622) 5 (cached) result: true 
2019-02-26 13:01:35: (configfile-glue.c.694) === start of condition block === 
2019-02-26 13:01:35: (configfile-glue.c.622) 6 (cached) result: false 
2019-02-26 13:01:35: (configfile-glue.c.694) === start of condition block === 
2019-02-26 13:01:35: (configfile-glue.c.622) 7 (cached) result: skipped 
2019-02-26 13:01:35: (configfile-glue.c.694) === start of condition block === 
2019-02-26 13:01:35: (configfile-glue.c.622) 8 (cached) result: skipped 
2019-02-26 13:01:35: (configfile-glue.c.694) === start of condition block === 
2019-02-26 13:01:35: (configfile-glue.c.622) 9 (cached) result: skipped 
2019-02-26 13:01:35: (configfile-glue.c.694) === start of condition block === 
2019-02-26 13:01:35: (configfile-glue.c.622) 1 (cached) result: false 
2019-02-26 13:01:35: (configfile-glue.c.694) === start of condition block === 
2019-02-26 13:01:35: (configfile-glue.c.622) 2 (cached) result: false 
2019-02-26 13:01:35: (configfile-glue.c.694) === start of condition block === 
2019-02-26 13:01:35: (configfile-glue.c.622) 3 (cached) result: skipped 
2019-02-26 13:01:35: (configfile-glue.c.694) === start of condition block === 
2019-02-26 13:01:35: (configfile-glue.c.622) 4 (cached) result: false 
2019-02-26 13:01:35: (configfile-glue.c.694) === start of condition block === 
2019-02-26 13:01:35: (configfile-glue.c.622) 5 (cached) result: true 
2019-02-26 13:01:35: (configfile-glue.c.694) === start of condition block === 
2019-02-26 13:01:35: (configfile-glue.c.622) 6 (cached) result: false 
2019-02-26 13:01:35: (configfile-glue.c.694) === start of condition block === 
2019-02-26 13:01:35: (configfile-glue.c.622) 7 (cached) result: skipped 
2019-02-26 13:01:35: (configfile-glue.c.694) === start of condition block === 
2019-02-26 13:01:35: (configfile-glue.c.622) 8 (cached) result: skipped 
2019-02-26 13:01:35: (configfile-glue.c.694) === start of condition block === 
2019-02-26 13:01:35: (configfile-glue.c.622) 9 (cached) result: skipped 
2019-02-26 13:01:35: (mod_access.c.148) -- mod_access_uri_handler called 
2019-02-26 13:01:35: (configfile-glue.c.694) === start of condition block === 
2019-02-26 13:01:35: (configfile-glue.c.622) 1 (cached) result: false 
2019-02-26 13:01:35: (configfile-glue.c.694) === start of condition block === 
2019-02-26 13:01:35: (configfile-glue.c.622) 2 (cached) result: false 
2019-02-26 13:01:35: (configfile-glue.c.694) === start of condition block === 
2019-02-26 13:01:35: (configfile-glue.c.622) 3 (cached) result: skipped 
2019-02-26 13:01:35: (configfile-glue.c.694) === start of condition block === 
2019-02-26 13:01:35: (configfile-glue.c.622) 4 (cached) result: false 
2019-02-26 13:01:35: (configfile-glue.c.694) === start of condition block === 
2019-02-26 13:01:35: (configfile-glue.c.622) 5 (cached) result: true 
2019-02-26 13:01:35: (configfile-glue.c.694) === start of condition block === 
2019-02-26 13:01:35: (configfile-glue.c.622) 6 (cached) result: false 
2019-02-26 13:01:35: (configfile-glue.c.694) === start of condition block === 
2019-02-26 13:01:35: (configfile-glue.c.622) 7 (cached) result: skipped 
2019-02-26 13:01:35: (configfile-glue.c.694) === start of condition block === 
2019-02-26 13:01:35: (configfile-glue.c.622) 8 (cached) result: skipped 
2019-02-26 13:01:35: (configfile-glue.c.694) === start of condition block === 
2019-02-26 13:01:35: (configfile-glue.c.622) 9 (cached) result: skipped 
2019-02-26 13:01:35: (response.c.122) Response-Header: \nHTTP/1.1 401 Unauthorized\r\nContent-Type: text/html\r\nContent-Length: 351\r\nDate: Tue, 26 Feb 2019 21:01:35 GMT\r\nServer: lighttpd/1.4.45\r\n\r\n 

日志的这一部分将HOST的测试结果显示为192.168.1.20,返回true:

HTTP["host"] ( 192.168.1.20 ) compare to  192.168.1.20
5 (uncached) result: true 

但是,重定向似乎没有发生,下一步是返回未经授权的401。

我认为我缺少一些基本知识。

1 个答案:

答案 0 :(得分:1)

mod_auth可能在配置文件中的mod_redirect之前加载,因此,身份验证要求在重定向之前应用于请求。为了避免将有关重定向的信息泄漏给未授权用户,这通常是非常理想的行为。如果要首先执行重定向,则设置一个条件以应用重定向,并将身份验证要求应用于所有其他内容。

$HTTP["host"] == "192.168.1.20" {
    url.redirect = ( "" => "http://pihole.home.lan/" )
}
else {
    auth.require = ( ... )
}

根据您的多篇文章,很明显,您正在尝试创建一个比基本理解还要复杂的配置。在发布越来越多的越来越多的问题之前,请使用您要尝试的方法测试简单配置。一旦可以单独完成单个简单任务,那么您才应该考虑将其添加到现有配置中,然后再次进行测试。如果可行,那就太好了。如果它不起作用,请在发布更多问题并使人们猜测您的配置之前花费一些精力自行进行故障排除,我会注意到您还没有提供。您在互联网上的同伴不是千里眼。我们通常在故障排除方面会更好(例如,按照刚才提到的简单的基本步骤进行操作)。