Nginx + Python, Behind Multiple Proxies
Normally operates. The former method get the URI. (like classificados.fatimanews.com.brclassificados.bonitoinforma.com.brclassificados.portalaguasclaras.com.br
I use nginx. What would it take? Could you help me?
9 Replies
proxysetheader Host $host;
proxysetheader X-Real-Ip $remote_addr;
proxysetheader X-Forwarded-For $proxyaddxforwardedfor;
or if you run Django under uwsgi, it's uwsgipassheader, etc… See nginx docs for more info on that.
uwsgipassheader Host;
proxysetheader Host $http_host;
proxypassheader Host;
What I doing wrong? I really need it.
Thanks man for any help.
uwsgiparam QUERYSTRING $query_string;
uwsgiparam REQUESTMETHOD $request_method;
uwsgiparam CONTENTTYPE $content_type;
uwsgiparam CONTENTLENGTH $content_length;
uwsgiparam REQUESTURI $request_uri;
uwsgiparam PATHINFO $document_uri;
uwsgiparam DOCUMENTROOT $document_root;
uwsgiparam SERVERPROTOCOL $server_protocol;
uwsgiparam REMOTEADDR $remote_addr;
uwsgiparam REMOTEPORT $remote_port;
uwsgiparam SERVERPORT $server_port;
uwsgiparam SERVERNAME $server_name;
You probably want the bottom one.
It's not working,
I'm almost giving up a vps. :/
@onovaes:
I tried that and it did not work
uwsgipassheader Host;
proxysetheader Host $http_host;
proxypassheader Host;
What I doing wrong? I really need it.
Thanks man for any help.
You're mixing uwsgi and proxy pass. which is it? uwsgi or proxy?
I just want to resolve the error of the initial question.
I can not get the URL when using the HttpRequest.get_host () in Django / Python in some cases. Usually works, but in some cases, instead of receiving the URL, IP comes.
My specialty is not servers.
Excuse my ignorance.
location / {
uwsgipass djangoappskalist;
uwsgiparam CONTENTTYPE $content_type;
uwsgiparam CONTENTLENGTH $content_length;
uwsgiparam REQUESTURI $request_uri;
uwsgiparam PATHINFO $document_uri;
uwsgiparam DOCUMENTROOT $document_root;
uwsgiparam SERVERPROTOCOL $server_protocol;
uwsgiparam REMOTEADDR $remote_addr;
uwsgiparam REMOTEPORT $remote_port;
uwsgiparam SERVERPORT $server_port;
uwsgiparam SERVERNAME $server_name;
}
In my world, we use gunicorn (and therefore HTTP instead of uWSGI) and our front-end proxies pass the remote IP address in the X-Real-IP header, so we just proxypassheader X-Real-IP. So, I'm mostly guessing here. You'll probably need to do something like this:
uwsgi_param REMOTE_ADDR $http_x_real_ip;
Things will be different if your front-end isn't passing you X-Real-IP.
My google-fu was failing out on finding an example of uWSGI+nginx+X-Real-IP, unfortunately, so your mileage may vary. This is, in part, why I use gunicorn.