lighttpd的 - 改ip地址(lighttpd - redirect of ip addres

2019-10-29 08:57发布

我想一个ip地址,AS-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 

日志的这部分显示了主机192.168.1.20返回true测试:

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

然而,重定向似乎并没有发生,而下一个动作是回报未经授权401。

我想我失去了一些东西基本。

Answer 1:

是的mod_auth之前mod_redirect可能加载您的配置文件等认证要求被应用到重定向前的请求。 这往往是非常可取的行为是为了避免对重定向到未经授权的用户泄露信息。 如果你想先进行重定向,然后设置要应用重定向的条件,并应用所需的身份验证一切。

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

根据您的多个职位,很显然,你要创建一个配置比你的基本的了解更加复杂。 发布越来越多,越来越多,越来越多的问题之前,请先测试与你正在尝试做一个简单的配置。 一旦你得到它的工作全部由自己做单,简单的事情,只有这样,你认为它添加到您现有的配置,并再次测试。 如果一切正常,伟大的。 如果它不能正常工作,请张贴更多的问题,使人们猜测你的配置,我会注意到,你没有提供之前花一些自己的努力,故障排除。 您在互联网上的同行都没有千里眼。 我们只是往往更好地排除故障(例如,跟随刚才提到的简单,基本步骤)。



文章来源: lighttpd - redirect of ip address