Get real user IP in Wordpress behind NGINX using PHP

Open your WP config file and just place this block at the start of it just before the line you see below ..

// Code for showing correct client IP address
if ( isset( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) {
    $addrs = explode( ',', $_SERVER['HTTP_X_FORWARDED_FOR'] );
    $_SERVER['REMOTE_ADDR'] = $addrs[0];
}
// ** MySQL settings - You can get this info from your web host ** //