Yannick PEREIRA-REIS bio photo

Yannick PEREIRA-REIS

Full stack web developer Symfony2, VueJs and AngularJs in Lyon (France), I also play with DevOps tools like Docker, Vagrant, Elasticsearch, Logstash, Kibana, Supervisor, ...

Twitter LinkedIn Github

Docker

Define a header in haproxy configuration to set real client IP address

In haproxy, you can get the client IP address from the request and pass it to another prox or application with a header.

  • %[src] is the client IP address extracted from incoming request.
  • X-Real-IP is the header we use to transfer IP address value.
frontend all_https
  option forwardfor header X-Real-IP
  http-request set-header X-Real-IP %[src]

Configure a custom log format in Nginx

  • Add a custom log format named “realip” (but name it the way you want…)
log_format realip '$http_x_real_ip - $remote_user [$time_local] '
                    '"$request" $status $body_bytes_sent '
                    '"$http_referer" "$http_user_agent"';
  • Use it in your access_log directive
access_log /dev/stdout realip;
access_log /path_to/log/file realip;