request.is_secure()在双重代理后面返回False

时间:2016-03-19 21:22:08

标签: django apache nginx proxy

如何在双重代理后面使request.is_secure()显示为真?

目前,只有一个https的nginx是公共的,它代理一个实际上托管Django应用程序的http唯一的apache实例。我需要在配置中更改某些内容吗?

Nginx的

location / {
    proxy_pass_header Server;
    proxy_set_header Host $http_host;
    proxy_redirect off;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Scheme $scheme;
    proxy_connect_timeout 6000;
    proxy_read_timeout 6000;
    proxy_pass http://127.0.0.1:9000;
}

的Apache

<VirtualHost *:9000>
    ServerName example.com

    ### Logs ###
    LogFormat "%h %l %u %t \"%r\" %>s %b %D" common
    ErrorLog ${APACHE_LOG_DIR}/error.log

    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel warn

    CustomLog ${APACHE_LOG_DIR}/access.log combined


    ### Site specific WSGI file ###
    WSGIApplicationGroup %{GLOBAL}

    KeepAlive Off
    WSGIDaemonProcess example.com processes=1 threads=20 inactivity-timeout=20
    WSGIProcessGroup %{GLOBAL}
    WSGIScriptAlias / "/usr/src/current/conf/apache/script.wsgi.py"
    WSGIPassAuthorization On

    <Directory "/">
        Options -Indexes
        Require all granted
    </Directory>
</VirtualHost>

1 个答案:

答案 0 :(得分:1)

您可以使用SECURE_PROXY_SSL_HEADER

如果我读好您的配置,我认为这应该有效:

SECURE_PROXY_SSL_HEADER = ('HTTP_X_SCHEME', 'https')