OpenBSD httpd.conf 条件

Bex*_*Bex 5 openbsd webserver http openbsd-httpd

注意:这个问题是关于内置的 OpenBSD http 服务器的命名httpd及其配置。它不适用于任何其他网络服务器。

\n\n

是否可以对新的 OpenBSD http 服务器进行运行时条件配置httpd?na\xc3\xafve 的例子是

\n\n
server "myserver.com" {\n  if $REMOTE_ADDR == "127.0.0.1" block drop\n}\n
Run Code Online (Sandbox Code Playgroud)\n\n

禁止本地访问。

\n\n

另一个也许更相关和更具启发性的例子是,我正在实现一个从特定位置运行的远程服务的接口,那么我将受益于类似的东西

\n\n
remote_service1_ip = "192.168.0.1"\nserver "myserver.com" {\n  location "/remote_service1_api/" {\n    if $REMOTE_ADDR != $remote_service1_ip block drop\n  }\n}\n
Run Code Online (Sandbox Code Playgroud)\n\n

如果这是可能的,正确的做法是什么?

\n\n

man更一般地说 - OpenBSD 的页面httpd.conf中指定了许多预定义的宏,如下所述block

\n\n
$DOCUMENT_URI\n    The request path.\n$QUERY_STRING\n    The optional query string of the request.\n$REMOTE_ADDR\n    The IP address of the connected client.\n$REMOTE_PORT\n    The TCP source port of the connected client.\n$REMOTE_USER\n    The remote user for HTTP authentication.\n$REQUEST_URI\n    The request path and optional query string.\n$SERVER_ADDR\n    The configured IP address of the server.\n$SERVER_PORT\n    The configured TCP server port of the server.\n$SERVER_NAME\n    The name of the server.\n%n\n    The capture index n of a string that was captured by the enclosing location match option.\n
Run Code Online (Sandbox Code Playgroud)\n\n

我想知道如何使用它们。在重定向上下文中使用$REMOTE_ADDR对我来说似乎相当愚蠢,我想应该有其他用途可以使用它们,但我在文档中找不到或理解任何此类用例。

\n

jit*_*ter 5

虽然httpd支持在某些关键字 ( ,, )patterns的上下文中使用,但您正在寻找的功能未在 中实现。alias matchlocation matchserver matchhttpd

我看到有两种方法可以实现你的意图:

  1. 邮件列表上的 crosspost openbsd-misc- 的作者之一httpd可能会在那里接你
  2. 用于pf防火墙。由于各种原因,我强烈推荐这种方式,包括
    • httpd由于应用程序 ( ) 不必承受任何负载,因此可以针对拒绝服务类型的攻击提供更高级别的保护
    • 来自客户端的数据包可以在全局 ( IP) 范围内进行检查和阻止 - 即泛洪客户端可能无法连接到该ssh端口

我认为,pf学习是一件非常令人满意的事情。

此外,我怀疑对相应帖子的可能答案openbsd-misc与我的建议类似:)