WebFaction
Community site: login faq

Writing some comments moderation stuff I accidentally noticed that all comments have 127.0.0.1 as the IP they were sent from. Some googling led me to this page, which says it's an issue with Webfaction reverse proxy, and that I have to use django.middleware.http.SetRemoteAddrFromForwardedFor to fix that. The middleware, however, has been removed from Django since the version 1.1, which mean that both the article I found that stuff written about Webfaction's reverse proxy and the code in the middleware are quite old now. So, the questions I want to ask are:

  • Is that (e. g. Webfaction reverse proxy) still the case?
  • Will the code from old Django (which can be found here) work correctly for the case?
  • Or how about this middleware? Is it for the same case? Will it work? Which one is better to use?

UPDATE: Solved by adding a middleware according to this link.

The walk-through, in case it may save someone a couple of minutes:

Create a file wfmiddleware.py in the project directory (say, "mysite") with this content:

class WebFactionFixes(object):
    def process_request(self, request):
        if 'HTTP_X_FORWARDED_FOR' in request.META:
            ip = request.META['HTTP_X_FORWARDED_FOR'].split(",")[0].strip()
            request.META['REMOTE_ADDR'] = ip

To MIDDLEWARE_CLASSES in the project's settings.py add 'mysite.wfmiddleware.WebFactionFixes'

Done!

asked 08 Nov '12, 07:18

nuigurumi
381610
accept rate: 0%

edited 09 Nov '12, 05:19


You would need to create your own middleware to pass that to Django. We have an example in our docs here. As well, there is some good information here.

permanent link

answered 08 Nov '12, 12:14

bmeyer71 ♦♦
1.5k3613
accept rate: 33%

Seems to work, thank you.

(08 Nov '12, 23:13) nuigurumi

You are very welcome. If you would like to share, with others, how you implemented your solution, please post an update to your question.

(09 Nov '12, 00:16) bmeyer71 ♦♦

I just did it according to the first link from your answer, but ok, I have updated the question with the detailed explanation, guess it may save someone a minute or two.

(09 Nov '12, 05:22) nuigurumi
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×910

question asked: 08 Nov '12, 07:18

question was seen: 3,393 times

last updated: 09 Nov '12, 05:22

                              
WEBFACTION
REACH US
SUPPORT
LEGAL
© COPYRIGHT 2003-2021 SWARMA LIMITED - WEBFACTION IS A SERVICE OF SWARMA LIMITED
REGISTERED IN ENGLAND AND WALES 5729350 - VAT REGISTRATION NUMBER 877397162
5TH FLOOR, THE OLD VINYL FACTORY, HAYES, UB3 1HA, UNITED KINGDOM