Apache modsec + ssl プロキシ ループ

Apache modsec + ssl プロキシ ループ

次のような設定のサーバーがあります。

http://example.com -(REDIRECT)-> https://example.com

ここで、次の操作を実行する単純な SSL プロキシ (A レコードが指しているのと同じマシン上) を追加します。

https://otherexample.com -(PROXY)-> https://example.com/a-uri

何らかの理由で、常にループに陥ってしまいます。modsecurity ログには次のように表示されます。

GET /a-uri/a-uri/a-uri/a-uri/a-uri/a-uri/a-uri/a-uri/a-uri/...
HTTP/1.1
Host: otherexample.com
Cache-Control: max-age=0
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 11_0_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
Sec-Fetch-Site: none
Sec-Fetch-Mode: navigate
Sec-Fetch-User: ?1
Sec-Fetch-Dest: document
Accept-Encoding: gzip, deflate, br
Accept-Language: nl-BE,nl;q=0.9
X-Forwarded-For: CLIENTIP, SERVERIP, SERVERIP, SERVERIP, ...
X-Forwarded-Host: otherexample.com, otherexample.com, otherexample.com, ...
X-Forwarded-Server: otherexample.com, otherexample.com, otherexample.com, ...

試した Apache 設定:

ProxyPreserveHost On
SSLEngine on
SSLProxyEngine on
SSLProxyVerify none
SSLProxyCheckPeerCN off
SSLProxyCheckPeerName off
SSLProxyCheckPeerExpire off


ProxyPass / https://example.com/a-uri/
ProxyPassReverse / https://example.com/a-uri/

書き換えエンジン:

RewriteRule ^/(.*) https://example.com/a-uri/$1 [P,l]

答え1

明らかに、各リクエストの URL の先頭に追加して、再度処理するために送り返すことRewriteRuleで、ループが発生しています。/a-uri

このディレクティブがサーバー全体の構成の一部であるかどうかは述べられていませんが、おそらくそうであると思われます。これは otherexample.com の仮想ホスト内に含まれているはずなので、そのホストにのみ適用されます。次のようになります。

<VirtualHost *:443>
  ServerName otherexample.com
  RewriteEngine on
  RewriteRule ^/(.*) https://example.com/a-uri/$1 [P,L]
</VirtualHost>

あるいは、もっと明確に言えば:

<VirtualHost *:443>
  ServerName otherexample.com
  ProxyPass        / https://example.com/a-uri/
  ProxyPassReverse / https://example.com/a-uri/
</VirtualHost>

答え2

Apache の問題を解決できませんでした。nginx プロキシを試してみましたが、多くの問題もなく、うまく機能しているようです。

関連情報