Linux 4 All

Best Linux tricks source

When Nginx is running on a server behind a Load Balancer, by default all traffic will come from Load Balancer IP, thus Nginx will only log the Load Balancer IP. In order to get your visitor real IP address, you can use X-Forwarded-For header.

In order to configure Nginx to log real IP address, add the following to nginx.conf, http section:

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';
    set_real_ip_from; # Varnish IP address
    set_real_ip_from; # Load Balancer IP range

    real_ip_header X-Forwarded-For;
    real_ip_recursive on;

PHP-FPM with Apache 2.4 and mod_proxy_fcgi arrow-right
Next post

arrow-left Nice and useful curl output
Previous post

Leave a Reply

Your email address will not be published. Required fields are marked *