Juil 272012
 

Si varnish est bien configuré, il envoie l’IP du client dans le paramètre HTTP X-Forwarded-For.

Pour le voir dans les logs apache2, il faut modifier le LogFormat utilisé et remplacer %h par %{X-Forwarded-For}i :

LogFormat "%v:%p %{X-Forwarded-For}i %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined

Si vous avez du https ou d’autre accès au apache2 sans varnish, vous ne verrez pas l’IP client. Pour cela on peut avoir 2 LogFormats différents en fonction de l’IP source de la requête :

LogFormat "%v:%p %{X-Forwarded-For}i %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined
LogFormat "%v:%p %h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined_direct
 
SetEnvIf Remote_Addr '^127.0.0.' varnish
CustomLog /var/log/apache2/other_vhosts_access.log vhost_combined env=varnish
CustomLog /var/log/apache2/other_vhosts_access.log vhost_combined_direct env=!varnish

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre lang="" line="" escaped="" cssfile="">

(required)

(required)

Spam protection by WP Captcha-Free