14👍
Try this one:
location / {
proxy_pass http://frontends;
proxy_pass_header Server;
proxy_redirect off;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Scheme $scheme;
proxy_set_header REMOTE_ADDR $remote_addr;
}
Just add proxy_set_header REMOTE_ADDR
and it should be work well.
Tried with:
- Django 1.5.4
- Nginx 1.4.3
- Tornado 2.2.1
17👍
Here’s how I solved the problem. By using this middleware:
class SetRemoteAddrMiddleware(object):
def process_request(self, request):
if not request.META.has_key('REMOTE_ADDR'):
try:
request.META['REMOTE_ADDR'] = request.META['HTTP_X_REAL_IP']
except:
request.META['REMOTE_ADDR'] = '1.1.1.1' # This will place a valid IP in REMOTE_ADDR but this shouldn't happen
Hope that helps!
- How to get max value in django ORM
- How to make trailing slash optional in django
- Performance comparison of using django signed cookie session over django db + cache based session?
- Django-filter messing around with empty field
5👍
I have a similar setup. After putting nginx in front of apache, I noticed that the IP in the apache logs was always 127.0.0.1. Installing “libapache2-mod-rpaf” seemed to fix it. I have no idea if your problem is related.
- Object of type 'TypeError' is not JSON serializable
- Jquery ajax form success callback not being called
- Performing non-blocking requests? – Django
- Override signup view django-allauth
5👍
Add “fastcgi_param REMOTE_ADDR $remote_addr;” to the nginx.conf file:
location / {
# host and port to fastcgi server
fastcgi_pass 127.0.0.1:8801;
fastcgi_param PATH_INFO $fastcgi_script_name;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_pass_header Authorization;
fastcgi_intercept_errors off;
...
# Add this line!
fastcgi_param REMOTE_ADDR $remote_addr;
...
}
- Strategies to make a web application available offline?
- Django – how can I access the form field from inside a custom widget
2👍
No, it’s not possible to pass on remote_addr. So the only solution that I know of is to use X-Real-IP or X-Forwarded-For and make sure that the backend handles these correctly.
Edit: this applies to fastcgi_pass, not regular nginx proxy_pass
- Compacting/minifying dynamic html
- How to layout a queue/worker structure to support large tasks for multiple environments?
2👍
For me, using the following worked:
server {
listen 80;
server_name foo.bar.com;
location / {
proxy_pass http://127.0.0.1:8000;
proxy_set_header X-Forwarded-For $remote_addr;
}
}
This works with django 1.4 (specifically, localshop).
- Celerybeat automatically disables periodic task
- Django cache framework. What is the difference between TIMEOUT and CACHE_MIDDLEWARE_SECONDS?
- Django SQL query duplicated n times
- Pip / virtualenv / django installation issue