Linode Forum
Linode Community Forums
 FAQFAQ    SearchSearch    MembersMembers      Register Register 
 LoginLogin [ Anonymous ] 
Post new topic  Reply to topic
Author Message
PostPosted: Fri Apr 20, 2012 3:33 pm 
Offline
Senior Newbie

Joined: Fri Apr 20, 2012 3:27 pm
Posts: 5
AOL: Rua+Turiassu,+552+ap+7
Location: Brazil
Use in programming (Python / Django) a method HttpRequest.get_host () (# https://docs.djangoproject.com/en/dev/r ... -response/ django.http.HttpRequest.get_host) but this method fails when the host is behind multiple proxies. In my application redirect some subdomains for her, and through the method mentioned recognize the subdomain in question.

Normally operates. The former method get the URI. (like [url]classificados.fatimanews.com.br[/url], [url]classificados.bonitoinforma.com.br[/url]) but today I created a subdomain ([url]classificados.portalaguasclaras.com.br[/url]), pointed to the IP of the machine, as I always do, and it happens that this time the method returns the IP of the machine and not the URL for me to identify it.

I use nginx. What would it take? Could you help me?


Top
   
 Post subject:
PostPosted: Fri Apr 20, 2012 5:07 pm 
Offline
Senior Member

Joined: Mon Dec 07, 2009 6:46 am
Posts: 331
I don't know which HTTP header exactly Django recognizes, I use Pyramid. And for that I set a combination of:

proxy_set_header Host $host;
proxy_set_header X-Real-Ip $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

or if you run Django under uwsgi, it's uwsgi_pass_header, etc... See nginx docs for more info on that.


Top
   
 Post subject:
PostPosted: Fri Apr 20, 2012 11:27 pm 
Offline
Senior Newbie

Joined: Fri Apr 20, 2012 3:27 pm
Posts: 5
AOL: Rua+Turiassu,+552+ap+7
Location: Brazil
I tried that and it did not work

uwsgi_pass_header Host;
proxy_set_header Host $http_host;
proxy_pass_header Host;

What I doing wrong? I really need it.

Thanks man for any help.


Top
   
 Post subject:
PostPosted: Sat Apr 21, 2012 5:19 am 
Offline
Senior Member

Joined: Sun Mar 07, 2010 7:47 pm
Posts: 1970
Website: http://www.rwky.net
Location: Earth
This is what I pass when using uwsgi

uwsgi_param QUERY_STRING $query_string;
uwsgi_param REQUEST_METHOD $request_method;
uwsgi_param CONTENT_TYPE $content_type;
uwsgi_param CONTENT_LENGTH $content_length;

uwsgi_param REQUEST_URI $request_uri;
uwsgi_param PATH_INFO $document_uri;
uwsgi_param DOCUMENT_ROOT $document_root;
uwsgi_param SERVER_PROTOCOL $server_protocol;

uwsgi_param REMOTE_ADDR $remote_addr;
uwsgi_param REMOTE_PORT $remote_port;
uwsgi_param SERVER_PORT $server_port;
uwsgi_param SERVER_NAME $server_name;

You probably want the bottom one.

_________________
Paid support
How to ask for help
1. Give details of your problem
2. Post any errors
3. Post relevant logs.
4. Don't hide details i.e. your domain, it just makes things harder
5. Be polite or you'll be eaten by a grue


Top
   
 Post subject:
PostPosted: Sat Apr 21, 2012 9:12 am 
Offline
Senior Newbie

Joined: Fri Apr 20, 2012 3:27 pm
Posts: 5
AOL: Rua+Turiassu,+552+ap+7
Location: Brazil
I already use these settings.

It's not working,

I'm almost giving up a vps. :/


Top
   
 Post subject:
PostPosted: Sat Apr 21, 2012 12:54 pm 
Offline
Senior Member

Joined: Mon Dec 07, 2009 6:46 am
Posts: 331
onovaes wrote:
I tried that and it did not work

uwsgi_pass_header Host;
proxy_set_header Host $http_host;
proxy_pass_header 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?


Top
   
 Post subject:
PostPosted: Sat Apr 21, 2012 8:13 pm 
Offline
Senior Newbie

Joined: Fri Apr 20, 2012 3:27 pm
Posts: 5
AOL: Rua+Turiassu,+552+ap+7
Location: Brazil
Sorry, but I do not know what I want. I do not know is if I want uwgi or proxies.
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.


Top
   
 Post subject:
PostPosted: Sat Apr 21, 2012 10:08 pm 
Offline
Senior Member
User avatar

Joined: Sat Aug 30, 2008 1:55 pm
Posts: 1739
Location: Rochester, New York
If you paste your config file here, it will be quite useful for figuring out what your configuration is.

_________________
Code:
/* TODO: need to add signature to posts */


Top
   
 Post subject:
PostPosted: Sat Apr 21, 2012 10:18 pm 
Offline
Senior Newbie

Joined: Fri Apr 20, 2012 3:27 pm
Posts: 5
AOL: Rua+Turiassu,+552+ap+7
Location: Brazil
my current settgins

location / {
uwsgi_pass djangoapp_skalist;

uwsgi_param CONTENT_TYPE $content_type;
uwsgi_param CONTENT_LENGTH $content_length;

uwsgi_param REQUEST_URI $request_uri;
uwsgi_param PATH_INFO $document_uri;
uwsgi_param DOCUMENT_ROOT $document_root;
uwsgi_param SERVER_PROTOCOL $server_protocol;

uwsgi_param REMOTE_ADDR $remote_addr;
uwsgi_param REMOTE_PORT $remote_port;
uwsgi_param SERVER_PORT $server_port;
uwsgi_param SERVER_NAME $server_name;

}


Top
   
 Post subject:
PostPosted: Sun Apr 22, 2012 12:47 pm 
Offline
Senior Member
User avatar

Joined: Sat Aug 30, 2008 1:55 pm
Posts: 1739
Location: Rochester, New York
You are using uWSGI.

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 proxy_pass_header X-Real-IP. So, I'm mostly guessing here. You'll probably need to do something like this:

Code:
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.

_________________
Code:
/* TODO: need to add signature to posts */


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
RSS

Powered by phpBB® Forum Software © phpBB Group