lighttpd - ip地址的重定向

问题描述 投票:0回答:1

我正在尝试将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。

我想我错过了一些基本的东西。

redirect lighttpd http-redirect
1个回答
1
投票

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

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

根据您的多个帖子,很明显您正在尝试创建比您的基本理解更复杂的配置。在发布越来越多越来越多的问题之前,请测试一下您尝试做的简单配置。一旦你让它自己完成一个单一的,简单的事情,那么你应该考虑将它添加到现有的配置中,然后再进行测试。如果它有效,那很好。如果它不起作用,请在发布更多问题并让人们猜测您的配置之前自己花一些精力进行故障排除,我会注意到您没有提供。你在互联网上的同行不是透视。我们通常更擅长排除故障(例如,遵循刚才提到的简单基本步骤)。

© www.soinside.com 2019 - 2024. All rights reserved.