【问题标题】:Config apache to not use x-forwarded-host header to be a host name将 apache 配置为不使用 x-forwarded-host 标头作为主机名
【发布时间】:2018-09-28 10:32:04
【问题描述】:

如果我的请求有超过 1 个的 x-forwarded-host 标头,我通过 K8 入口向 Apache 请求时收到 400 错误请求

www.a.com, www.b.com

我从这个请求中记录 Apache,Apache 使用 x-forwarded-host 作为主机名。 Apache 日志是这样的

[core:debug] [pid 18] vhost.c(796): [client 172.17.0.7:51726] AH02415: [strict] Invalid host name 'www.a.com,www.b.com', 问题附近:,www.b

[core:debug] [pid 18] vhost.c(891): [client 172.17.0.7:51726] AH00550:客户端发送的主机头格式错误:www.a.com,www.b.com

[core:debug] [pid 18] protocol.c(1393): [client 172.17.0.7:51726] AH00569: 客户端发送的 HTTP/1.1 请求没有主机名(参见 RFC2616 第 14.23 节):/ [headers:debug] [pid 18] mod_headers.c(900): AH01503: headers: ap_headers_error_filter() 172.17.0.5:80 172.17.0.7 - - [28/Sep/2018:10:27:44 +0000] "GET / HTTP/1.1" 400 0 "-" ""

我必须配置 Apache 不要使用 x-forward-host 作为主机名。我如何在 Apache 中配置它?

【问题讨论】:

    标签: apache kubernetes


    【解决方案1】:

    该标头由 Apache 前面的设备发送。该设备作为代理添加此标头。所以你正在接收它。如果您不希望它出现在日志中,请更改日志的格式描述符。

    例如:默认的日志格式

    LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
    LogFormat "%h %l %u %t \"%r\" %>s %b" common
    

    还有我在生产服务器上使用的那个:

    LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
    

    我在定义 access_log 时使用它:

    CustomLog logs/access_log combined
    


    如果我删除 %{X-Forwarded-For}i 并将其替换为默认的 %h,则不再显示“双”主机名(或 IP)。

    如果这不适用于您的配置,请从您的配置文件中添加您的 LogFormat 和 CustomLog 指令,以便我们对其进行评论。

    【讨论】:

      猜你喜欢
      • 2013-10-05
      • 2017-09-27
      • 2020-01-25
      • 2011-01-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多