Skip to content

Commit

Permalink
Merge pull request #70 from pirate/patch-1
Browse files Browse the repository at this point in the history
Update docs to explain IP issues when django runs behind a proxy
  • Loading branch information
Bouke committed Mar 15, 2017
2 parents 2e42618 + 2684906 commit ece45f3
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions docs/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,18 @@ documentation on `installing GeoIP`_.

.. _installing GeoIP:
https://docs.djangoproject.com/en/1.6/ref/contrib/gis/geoip/

IP when behind a proxy
----------------------
If you're running Django behind a proxy like nginx, you will have to set
the `REMOTE_ADDR` META header manually using a middleware, to stop it from
always returning the ip of the proxy (e.g. 127.0.0.1 in many cases).

An example middleware to fix this issue is https://github.com/allo-/django-xforwardedfor-middleware
Which simply does this for each request:

``request.META['REMOTE_ADDR'] = request.META['HTTP_X_FORWARDED_FOR'].split(',')[0].strip()``

Your particular configuration may vary, `X-Forwarded-For` must be set by
a proxy that you have control over, otherwise it might be spoofed by the
client.

0 comments on commit ece45f3

Please sign in to comment.