Open YPCrumble opened 5 years ago
In a Chrome incognito window,
REMOTE_ADDR
is a null value
Is that true? I haven't tested it but it doesn't sound right at all. REMOTE_ADDR is set by the wsgi handler, and it should always be set -- I've seen it be null, but it was usually due to broken serverside config.
@jleclanche I apologize, you're correct in that my reasoning is wrong. I believe the issue is that I'm using an NGINX reverse proxy and so REMOTE_ADDR will always be blank. See for instance this stackoverflow answer.
I believe this is always the case in NGINX but if you happen to know of a solution I'd love to hear it! Here's my current proxy config below. You'll notice that I do set the X-Forwarded-For
header which contains the user's IP address but not sure about how to set the REMOTE_ADDR header.
location / {
if (-f {{ virtualenv_path }}/maintenance_on.html) {
return 503;
}
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
proxy_set_header Host $http_host;
proxy_redirect off;
# Try to serve static files from nginx, no point in making an
# *application* server like Unicorn/Rainbows! serve static files.
if (!-f $request_filename) {
proxy_pass http://{{ application_name }}_wsgi_server;
break;
}
}
My current solution is to use the middleware suggested in that StackOverflow answer, but if you have another better suggestion, or if you'd like me to submit a PR to check the X-Forwarded-For
header first, or any other solution please do let me know.
Thanks again for open sourcing this app! Super helpful on my site :).
X-Forwarded-For can be faked by users so it's preferable not to rely on it.
Thanks for building this!
In a Chrome incognito window,
REMOTE_ADDR
is a null value so this library throws the IntegrityError above.I suggest allowing
null=True, blank=True
on this field to allow blank values. Happy to add a PR if that's helpful! Let me know if any suggestions or concerns?