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 프록시를 사용해 보았는데 많은 문제 없이 더 잘 작동하는 것 같습니다.

관련 정보