【问题标题】:Can you edit the headers of an incoming request in Apache httpd v2.4.6?您可以在 Apache httpd v2.4.6 中编辑传入请求的标头吗?
【发布时间】:2020-06-17 20:39:09
【问题描述】:

Apache 文档说明 ProxyPreserveHost:

启用后,此选项会将 Host: 行从传入请求传递到代理主机

否则:

ProxyPass 行中指定的主机名(已使用)

在 Apache conf 中,有没有办法将自定义主机设置为不是其中任何一个的主机?
例如ProxySetHost customHostName

//编辑
在nginx中,可以使用这个注解:

nginx.ingress.kubernetes.io/proxy-ssl-name
允许设置 proxy_ssl_name。这允许覆盖用于验证代理 HTTPS 服务器证书的服务器名称。当与代理 HTTPS 服务器建立连接时,此值也会通过 SNI 传递。

Apache httpd 中有类似的东西吗?

【问题讨论】:

  • ProxyPreserveHost 表示它将在浏览器中保留相同的 Apache httpd 主机并从后端服务器获取数据,而无需更改浏览器中的 HostName。更改 URL 中的主机名有什么具体要求吗?
  • @Pandurang 我想将代理请求反向到 nginx 中的特定服务器块。这需要我将请求中的 Host 设置为相应的服务。我无法在 ProxyPass 行中设置它,因为它必须设置为 ip,因为我无法更改 DNS。
  • 如果您使用 Apache httpd 作为前端,使用 Nginx 作为反向代理,那么只有 Apache HostName 对用户或浏览器可见。
  • @Pandurang 我使用 Apache httpd 作为 nginx 的反向代理。不确定你的意思是否相同。您是说无法将主机设置为其他内容(减去 ProxyPass 和 ProxyPreserveHost)?

标签: apache


【解决方案1】:

我想我找到了自己的答案。更清楚地说,我正在寻找一种方法来修改通过 SNI 扩展发送的主机,该扩展发生在我的 apache 前端和 nginx 后端之间发送 http 标头之前。使用 SSLProxyPreserveHost 时似乎设置了 SNI,如果您查看模块的源代码(但不在文档中),这一点很明显。

我在github上翻了一下httpd的proxy模块源码,貌似只有3种情况下SNI主机改了:

(proxy_util.c - https://github.com/apache/httpd/blob/trunk/modules/proxy/proxy_util.c)

案例1:(由注释块解释)

        /*
         * In the case of ProxyPreserveHost on use the hostname of
         * the request if present otherwise use the one from the
         * backend request URI.
         */
        dconf = ap_get_module_config(r->per_dir_config, &proxy_module);
        if (dconf->preserve_host) {
            ssl_hostname = r->hostname;
        }

案例 2:认为只有设置了正向代理才会发生(我正在使用反向代理)。

        else if (conn->forward
                 && ((forward_info *)(conn->forward))->use_http_connect) {
            ssl_hostname = ((forward_info *)conn->forward)->target_host;
        }

案例 3:否则设置为 ProxyPass 行中指定的主机。

        else {
            ssl_hostname = conn->hostname;
        }

我为 httpd 的一个错误报告添加了评论,如果有人有兴趣关注它,请链接:https://bz.apache.org/bugzilla/show_bug.cgi?id=64422

【讨论】:

    猜你喜欢
    • 2016-03-18
    • 2021-09-23
    • 2021-08-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-15
    • 1970-01-01
    • 2011-09-01
    相关资源
    最近更新 更多