简体   繁体   中英

Django not recognizing ssl related os.environ

I have Django installed on a corporate intranet, running on Apache using mod_wsgi. The Apache server has SSL set up, and everything is working as expected when users hit CGI pages, but my django applications don't seem to be picking up any SSL related environment variables (ssl_client_s_dn, etc) whether they go to my django pages with http:// or https://.

I think the main issue is that I don't understand where django is pulling it's os.environ from, and how to change that. I've looked through the official django documentation and other posts on 'django' and 'ssl', but those seem to deal with views that need to sometimes be http, and sometimes https. I am just trying to get ssl related information to show up in os.environ at all, and I don't know where to look next.

What do you need to know? httpd.conf wsgi configuration settings? My projects settings.py, or lines in wsgi.py?

Any help is much appreciated.

If you are using mod_wsgi within Apache, and you set the environment variables in Apache (using SetEnv ), then you are out of luck: mod_wsgi 's environment variables are separate from these in Apache.

Many people are running into similar problems, when setting variable in Apache using SetEnv is completely invisible when trying to access os.environ in Django.

There is however some solution. It is listed here , and basically comes to these lines in your wsgi script (adjusted to your needs):

def application(environ, start_response):
    os.environ['ssl_client_s_dn'] = environ['ssl_client_s_dn']
    return _application(environ, start_response)

Which basically translates first argument of your WSGI application into os.environ dictionary. For details see the post linked above.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM