Apache modsec + loop de proxy SSL

Apache modsec + loop de proxy SSL

Eu tenho um servidor onde temos a seguinte configuração:

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

Agora gostaríamos de adicionar um proxy SSL simples (na mesma máquina para onde o registro A também está apontando) que fará o seguinte:

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

Por alguma razão sempre terminamos em loop, é isso que o log do modsecurity mostra:

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, ...

Configurações do Apache que eu tentei:

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/

Mecanismo de reescrita:

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

Responder1

Isso RewriteRuleestá claramente causando o loop, acrescentando /a-urio URL de cada solicitação e enviando-o de volta para ser processado novamente.

Você não diz se essa diretiva faz parte da configuração de todo o servidor, mas parece que provavelmente faz. Ele deve estar contido no host virtual de otherexample.com, portanto, aplica-se apenas a esse host. Assim:

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

Ou talvez mais claro:

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

Responder2

Não consegui resolver o problema com o Apache. Tentamos um proxy nginx e parece funcionar melhor para nós sem muitos problemas.

informação relacionada