Résoudre REMOTE_ADDR derrière un reverse proxy Varnish

Lorsqu’un site est derrière un reverse proxy (comme Varnish Cache), le php ne reçoit dans la variable $_SERVER[‘REMOTE_ADDR’] que l’adresse IP du reverse proxy. Afin d’accéder à l’IP du client, il faut ajouter une directive au fichier VCL de Varnish et modifier le code php permettant de récupérer l’ip.

 

Ajout dans le fichier .vcl de Varnish

sub vcl_recv {
if (req.restarts == 0) {
if (req.http.x-forwarded-for) {
set req.http.X-Forwarded-For =
req.http.X-Forwarded-For + ", " + client.ip;
} else {
set req.http.X-Forwarded-For = client.ip;
}
}

Dans le php, on récupère l’IP du client en utilisant

$dotted_ip_address = $_SERVER['HTTP_X_FORWARDED_FOR'];

 Résoudre REMOTE_ADDR derrière un reverse proxy Varnish

Tagged in:,

86 Comments

  1. z888gamelogin

    18 août 2026 - 6 h 40 min
    Reply

    Logging in is actually effortless on this platform which saves me so much hassle. I love how the game library updates regularly and the security keeps my account completely safe. If you want a hassle free gaming experience just give this a shot z888gamelogin

  2. clbcgame

    18 août 2026 - 6 h 41 min
    Reply

    This platform has completely changed how I enjoy online entertainment. The interface is so clean and loading times are incredibly quick. I love the daily bonuses and the way they reward loyal players. It feels like a genuine place where everyone gets a fair shot at winning big. Give clbcgame a try today.

  3. vnuu88com

    9 septembre 2026 - 17 h 05 min
    Reply

    I have tried so many different sites but this one stands out for its genuine care towards users. Every update brings something new and the customer service team treats you like family. I cannot recommend it enough to fellow players looking for a solid routine. Discover the difference at vnuu88com

Leave a Reply

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *

Ce site utilise Akismet pour réduire les indésirables. En savoir plus sur la façon dont les données de vos commentaires sont traitées.