Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(SSL) Not able to set wsgi.url_scheme #51

Closed
gtaylor opened this issue May 13, 2010 · 12 comments
Closed

(SSL) Not able to set wsgi.url_scheme #51

gtaylor opened this issue May 13, 2010 · 12 comments

Comments

@gtaylor
Copy link
Contributor

gtaylor commented May 13, 2010

I'm trying to deploy for production with Nginx + gunicorn + Django.

I bet there's a better way to do this, but I can't figure out how to set the wsgi.url_scheme environmental variable on gunicorn Request objects. It looks like it's hard-wired to 'http' right now, whereas I need it to be 'https' for the SSL segment of my site. For mod_wsgi, the solution is to kludge it in your wsgi.conf.py file like this: http://gist.github.com/78416#file_django_satchmo.wsgi

Is there any way to do this with gunicorn?

@benoitc
Copy link
Owner

benoitc commented May 26, 2010

fixed in latest head : pass an Http header to gunicorn :

X-Forwarded-Protocol=https or X-Forwarded-Ssl=on

Thanks for the feedback.

  • benoit

@yashh
Copy link

yashh commented Jul 20, 2010

I set the X-Forwarded-Protocol to https in nginx config. I see that request.META.get('HTTP_X_FORWARDED_PROTOCOL') returns 'https'. But request.is_secure() is still false. Is it ok to write a decorator to check HTTP_X_FORWARDED_PROTOCOL and perform redirects to https ? or is there is a plan to get is_secure working in future.

@gtaylor
Copy link
Contributor Author

gtaylor commented Jul 20, 2010

Try adding the X-Forwarded-Ssl=on too.

@benoitc
Copy link
Owner

benoitc commented Jul 20, 2010

what are the worker and gunicorn version you're using ? What is the result of wsgi.url_scheme ? Please open a new issue about it btw.

@benoitc
Copy link
Owner

benoitc commented Jul 20, 2010

Oh it seems that your http headers are wrong. To have wsgi.url_scheme = "https" use X-Forwarded-Protocol: ssl or X-Forwarded-Ssl: on headers.

@yashh
Copy link

yashh commented Jul 20, 2010

I am using gunicorn 0.10 (yesterday's master). Currently my wsgi.url_scheme is http. I ll set the X-Forwarded-Protocol to ssl and let you how it works.

@yashh
Copy link

yashh commented Jul 20, 2010

Alright I configured nginx to set X-Forwarded-Protocol one time and X-Forwarded-Ssl the other time.

request.is_secure() is false in both cases. However this how request.META has

'HTTP_X_FORWARDED_PROTOCOL': 'ssl',
'wsgi.url_scheme': 'http',
'HTTP_X_FORWARDED_SSL': 'on'

@benoitc
Copy link
Owner

benoitc commented Jul 20, 2010

which worker ?

@gtaylor
Copy link
Contributor Author

gtaylor commented Jul 20, 2010

Perhaps even more importantly, which version of Django? I'm almost positive that request.is_secure() has changed in the last few releases, we had a similar problem.

@yashh
Copy link

yashh commented Jul 26, 2010

Sorry for the delay. I tried to push SSL on our prod servers and had problems with the config. Had to rollback. I will post my config in the next couple of days and explain in detail

@sidmitra
Copy link

I just stumbled upon this thread, i thought this might be relevant: http://github.com/rossdakin/django-heroism

@spookylukey
Copy link

Relevant Django ticket: http://code.djangoproject.com/ticket/14597

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants