DEV Community

David Silva
David Silva

Posted on

1

Bloquear Tráfego Por IP - X-Forwarded-For Apache 2.4

Quando seu apache recebe requisições de um LoadBalancer o IP de origem delas serão (claro) do LoadBalancer. Consequentemente, quando você precisar fazer algo como bloquear tráfegos indesejados por ip, o processo é um pouco diferente dos casos convencionais pois você não terá nas mãos o REMOTE_ADDR ou o simples ip, por exemplo.

No caso do exemplo abaixo, há um LoadBalancer redirecionando para o apache do servidor que ainda faz um proxy reverso para o container:

<VirtualHost *:443>
    <LocationMatch "/.*">
        Order Allow,Deny
        Allow from all
        ## você pode colocar uma lista de IPs
        SetEnvif X-Forwarded-For "xxx\.xxx\.xxx\.xxx" DenyAccess
        SetEnvif X-Forwarded-For "yyy\.yyy\.yyy\.yyy" DenyAccess
        Deny from env=DenyAccess
    </LocationMatch>

    ... # outras configs do seu serviço

    ProxyPreserveHost On
    ProxyRequests Off
    ProxyPass / http://container:port/ retry=1 timeout=180 nocanon
    ProxyPassReverse / http://container:port/
</VirtualHost>

Enter fullscreen mode Exit fullscreen mode

Se isso lhe foi útil, deixe seu comentário!

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay