# -*- coding: utf-8 -*-


def get_client_ip(request):
    ip = request.META.get('HTTP_X_FORWARDED_FOR')
    if ip:
        return ip.split(', ')[0]
    else:
        return request.META['REMOTE_ADDR']

# -*- coding: utf-8 -*-


def get_client_ip(request):
    ip = request.META.get('HTTP_X_FORWARDED_FOR')
    if ip:
        return ip.split(', ')[-1]
    else:
        return request.META['REMOTE_ADDR']

Fix client IP detection behind reverse proxy
Fix client IP detection behind reverse proxy

The `X-Forwarded-For` header can be easily spoofed by a client. When
forwarding a connection, nginx appends the real detected IP to the the
list. So, what we need is actually the last one on this list, not the
first one.
