gpt4 book ai didi

具有 SSL 终止功能的 Apache 转发代理

转载 作者:太空宇宙 更新时间:2023-11-03 12:43:54 25 4
gpt4 key购买 nike

我正在尝试设置终止 SSL 连接的 Apache 转发代理。我尝试这样做的原因是在返回的代码上运行 Apache 过滤器(特别是 mod_pagespeed )。在我处理 mod_pagespeed 之前,我通过尝试在响应中插入一个 header 来测试这个 POC(这将证明我可以编辑响应),但是我遇到了 SSL 代理问题(非 SSL 代理工作正常) .

请注意,我不担心任何证书错误或类似问题——这纯粹是为了内部测试。

我已经设置好服务器并在非 SSL 页面上看到 X-MSCProxy header :

jshannon-macbookpro:pagespeed_proxy jshannon$ curl -vv --proxy pagespeed_proxy:3ja82ad9@localhost:8080 -D - -o /dev/null http://www.slate.com

* TCP_NODELAY set
* Connected to localhost (::1) port 8080 (#0)
* Proxy auth using Basic with user 'pagespeed_proxy'
> GET http://www.slate.com/ HTTP/1.1
> Host: www.slate.com
...
>
< HTTP/1.1 200 OK
HTTP/1.1 200 OK
< Date: Mon, 30 Oct 2017 18:10:40 GMT
Date: Mon, 30 Oct 2017 18:10:40 GMT
< Server: Apache/2.2.29 (Amazon)
Server: Apache/2.2.29 (Amazon)
...
< Content-Length: 187051
Content-Length: 187051
...
< X-Instart-Request-ID: 8286987369135064135:FWP01-NPPRY22:1509387040:0
X-Instart-Request-ID: 8286987369135064135:FWP01-NPPRY22:1509387040:0
< Via: 1.1 172.17.0.2:8080
Via: 1.1 172.17.0.2:8080
< X-MSCProxy: SansPS
X-MSCProxy: SansPS

但是当我向 Slate 的 SSL 页面发出相同的请求时,我没有看到我的代理:

jshannon-macbookpro:pagespeed_proxy jshannon$ curl -vv --proxy pagespeed_proxy:3ja82ad9@localhost:8080 -D - -o /dev/null https://www.slate.com

* Connected to localhost (::1) port 8080 (#0)
* Establish HTTP proxy tunnel to www.slate.com:443
* Proxy auth using Basic with user 'pagespeed_proxy'
> CONNECT www.slate.com:443 HTTP/1.1
> Host: www.slate.com:443

< HTTP/1.0 200 Connection Established
HTTP/1.0 200 Connection Established
< Proxy-agent: Apache/2.4.25 (Debian)
Proxy-agent: Apache/2.4.25 (Debian)
<

* Proxy replied OK to CONNECT request
* TLS 1.2 connection using TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
* Server certificate: ssl004.insnw.net
* Server certificate: GlobalSign CloudSSL CA - SHA256 - G3
* Server certificate: GlobalSign Root CA
> GET / HTTP/1.1
> Host: www.slate.com
> User-Agent: curl/7.54.0
> Accept: */*
>

< Content-Length: 187044
Content-Length: 187044
< Connection: keep-alive
Connection: keep-alive
< Server: Apache/2.2.29 (Amazon)
Server: Apache/2.2.29 (Amazon)
< X-Instart-Request-ID: 762420041708891440:FWP01-NPPRY21:1509387251:0
X-Instart-Request-ID: 762420041708891440:FWP01-NPPRY21:1509387251:0

我发现很多帖子都说这是可能的(并且从技术上讲,它应该是)各种 httpd.conf 建议,但我尝试过的都没有奏效。现在我的 httpd.conf 看起来像:

<VirtualHost *:8080>
ProxyRequests On
ProxyVia On

Header set X-MSCProxy SansPS

#SSLEngine On
# suggestion that this allows termination
ProxyPreserveHost On

SSLProxyEngine on
SSLProxyCheckPeerCN Off
SSLProxyCheckPeerExpire Off
SSLProxyCheckPeerName Off

SSLCertificateFile /etc/apache2/ssl/localhost.crt
SSLCertificateKeyFile /etc/apache2/ssl/localhost.key

ModPagespeed Off
</VirtualHost>

FWIW,当我在此代理上启用 SSLEngine 时(如建议的那样),请求根本无法处理来自 Apache 的此错误:

[Mon Oct 30 18:20:20.705047 2017] [ssl:info] [pid 372:tid 140147985901312] [client 172.17.0.1:34012] AH01996: SSL handshake failed: HTTP spoken on HTTPS port; trying to send HTML error page
[Mon Oct 30 18:20:20.705107 2017] [ssl:info] [pid 372:tid 140147985901312] SSL Library Error: error:1407609C:SSL routines:SSL23_GET_CLIENT_HELLO:http request -- speaking HTTP to HTTPS port!?

我想这是有道理的,因为代理协议(protocol)并不期望直接与代理建立 HTTPS 连接。

最佳答案

我会尝试使用 apache 的输出过滤器功能。

https://www.modpagespeed.com/doc/configuration#apache_specific

AddOutputFilterByType MOD_PAGESPEED_OUTPUT_FILTER text/html

关于具有 SSL 终止功能的 Apache 转发代理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47021865/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com