AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 1091694
Accepted
Bernd Wechner
Bernd Wechner
Asked: 2022-01-31 21:06:24 +0800 CST2022-01-31 21:06:24 +0800 CST 2022-01-31 21:06:24 +0800 CST

Lighttpd URL 和主机匹配以及包含文件跨越(可能吗?)

  • 772

我有一个有趣的条件解析问题要解决,并且还没有在线搜索和查看 lighttpd 文档的运气。其中许多搜索导致了此处提出的类似问题和有用的答案(对于那些问题,让我们看看这个问题是如何运行的:

我在网关路由器(OpenWRT,或 Turris OS,如果您愿意,因为它是 Turris Omnia)上运行 lighttpd,并且它有许多域指向它的方式,作为 LAN 端服务器的反向代理网关。

一般配置是,在形式上,如:

$HTTP["host"] =~ "(a.com|b.com|c.com)$" {
    proxy.server  = ( "" => ( ( "host" => "..." ) ) )
    ...
} else $HTTP["host"] =~ "(d.org|e.org)$" {
    proxy.server  = ( "" => ( ( "host" => "..." ) ) )
    ...
} else $HTTP["host"] =~ "(f.net|g.net)$" {
    proxy.server  = ( "" => ( ( "host" => "..." ) ) )
    ...
}

多年来,这一直是一个梦想。

现在我想要一个特定的路径,所有这些站点都可以直接从这个路由器提供服务。

再次备考:

$HTTP["url"] =~ "^/topdir/subir/" {
    server.document-root = "/www/sharedstuff"
}

我可以将它完美地组合如下(并且有效):

$HTTP["url"] =~ "^/topdir/subir/" {
    server.document-root = "/www/sharedstuff"
} else {
   $HTTP["host"] =~ "(a.com|b.com|c.com)$" {
       proxy.server  = ( "" => ( ( "host" => "..." ) ) )
       ...
   } else $HTTP["host"] =~ "(d.org|e.org)$" {
       proxy.server  = ( "" => ( ( "host" => "..." ) ) )
       ...
   } else $HTTP["host"] =~ "(f.net|g.net)$" {
       proxy.server  = ( "" => ( ( "host" => "..." ) ) )
       ...
   }
}

甜的。

但是,这是我要解决的问题。理想情况下,我希望将$HTTP["url"]条件封装在一个包含的文件中,并将$HTTP["host"]条件封装在另一个文件中,以便我可以:

include "/etc/lighttpd/conf.d/shared.conf"      # contains the `$HTTP["url"]` constraint
include "/etc/lighttpd/conf.d/distributed.conf" # contains the `$HTTP["host"]` constraint

我想知道我是否对这里抱有太多期望。因为我想不出也想不出办法。

我想如果shared.conf包含一些语句,例如存在如下配置语句:

$HTTP["url"] =~ "^/topdir/subir/" {
    server.document-root = "/www/sharedstuff"
    ignore-all-subsequent-host-match-conditions 
}

另一个创造性的想法是,如果我们可以重写$HTTP["host"]类似于:

$HTTP["host"] = "null.net"

这样后续的匹配$HTTP["host"] =~ "(a.com|b.com|c.com)$"都失败了,请求保持在本地。

以下是迄今为止探索的一些选项:

服务器变量

不行,因为这些是在加载配置时而不是在处理请求时评估的。

https://redmine.lighttpd.net/projects/1/wiki/docs_configuration#Using-variables

请求标头

setenv.add-request-header看起来很有吸引力:

https://redmine.lighttpd.net/projects/lighttpd/wiki/Docs_ModSetEnv

如果 inshared.conf我们设置了一个自定义请求标头,也许我们可以使用$REQUEST_HEADER["header"]in对其进行测试distributed.conf:

https://redmine.lighttpd.net/projects/1/wiki/docs_configuration#Conditional-Configuration

但我没有取得任何成功。似乎有这样的条件:

$REQUEST_HEADER["my_header"] == "value_I_set" {
   # Do not act as a reverse proxy 
} else $HTTP["host"] =~ "(a.com|b.com|c.com)$" {
    proxy.server  = ( "" => ( ( "host" => "..." ) ) )
    ...
} else $HTTP["host"] =~ "(d.org|e.org)$" {
    proxy.server  = ( "" => ( ( "host" => "..." ) ) )
    ...
} else $HTTP["host"] =~ "(f.net|g.net)$" {
    proxy.server  = ( "" => ( ( "host" => "..." ) ) )
    ...
}

根本行不通,我无法真正猜到为什么。很难看到发生了什么,但如果我在条件处理上记录输出,即使对于匹配$REQUEST_HEADER["my_header"]的 URL,它似乎也总是空白:shared.conf

$HTTP["url"] =~ "^/topdir/subir/" {
    setenv.add-request-header = ("my_header" => "value_I_set")
}

似乎该条件并未测试 setenv 设置的请求标头,与交付的标头一样多。

configuration lighttpd reverse-proxy
  • 1 1 个回答
  • 203 Views

1 个回答

  • Voted
  1. Best Answer
    gstrauss
    2022-02-24T23:55:27+08:002022-02-24T23:55:27+08:00

    一种可能的配置解决方案是将您的共享配置放在条件之后$HTTP["host"],在您的情况下,覆盖代理配置

    $HTTP["url"] =~ "^/topdir/subir/" {
        server.document-root = "/www/sharedstuff"
        proxy.server = ()
    }
    

    另一种更灵活、更强大的解决方案:lighttpd mod_magnet允许您在几行 lua 中编写任意复杂的逻辑。您可以在 lighttpd mod_proxy 之前让您的“共享”配置处理某些请求(在您的自定义 lua 脚本中)。

    顺便说一句,以下幼稚的解决方案是否也有效?共享配置:

    $HTTP["url"] =~ "^/topdir/subir/" {
        server.document-root = "/www/sharedstuff"
    }
    

    在包含在 lighttpd.conf 中的 shared.conf 中

    include "/etc/lighttpd/conf.d/shared.conf"      # contains the `$HTTP["url"]` constraint
    else {
        include "/etc/lighttpd/conf.d/distributed.conf" # contains the `$HTTP["host"]` constraint
    }
    
    • 0

相关问题

  • 小型企业的服务器虚拟化/RAID 配置

  • httpd.conf 用于不区分大小写的文件服务

  • Windows Server 2003 DNS 添加的 CNAME 不起作用

  • 我应该使用什么策略在 linux 上安装 smtp 服务器?用于多线程服务

  • 为什么我的站点在配置为直通身份验证时使用 IUSR 帐户?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve