Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Django with mod_wsgi如何设置PYTHONHASHSEED env变量?_Python_Django_Mod Wsgi - Fatal编程技术网

Django with mod_wsgi如何设置PYTHONHASHSEED env变量?

Django with mod_wsgi如何设置PYTHONHASHSEED env变量?,python,django,mod-wsgi,Python,Django,Mod Wsgi,如何在PYTHONHASHSEED环境变量设置为random的情况下使用mod_wsgi运行django? 在django设置中设置它是一种好方法吗 os.environ['PYTHONHASHSEED'] = 'random' mod_wsgi 4.1.0为此()引入了一个选项;您需要将以下内容添加到Apache配置中: WSGIPythonHashSeed random 如果无法运行该版本,则必须在Apache进程的启动环境中设置变量,该环境是特定于操作系统的。对于Fedora或RHEL

如何在PYTHONHASHSEED环境变量设置为random的情况下使用mod_wsgi运行django? 在django设置中设置它是一种好方法吗

os.environ['PYTHONHASHSEED'] = 'random'

mod_wsgi 4.1.0为此()引入了一个选项;您需要将以下内容添加到Apache配置中:

WSGIPythonHashSeed random
如果无法运行该版本,则必须在Apache进程的启动环境中设置变量,该环境是特定于操作系统的。对于Fedora或RHEL 7,您可以创建/etc/systemd/system/httpd.service:

.include /lib/systemd/system/httpd.service
[Service]
Environment=PYTHONHASHSEED=random
然后
systemctl后台程序重新加载;systemctl重新启动httpd.service
。对于预systemd Red Hat,您可以编辑/etc/sysconfig/httpd。对于Debian,它是/etc/apache2/envvars

这里有一个WSGI文件来测试它是否工作(基于mod_WSGI文档中的示例):

import sys

def application(environ, start_response):
    status = '200 OK'

    try:
        hr = sys.flags.hash_randomization
        if hr == 0:
            output = 'Hash randomization disabled'
        elif hr == 1:
            output = 'Hash randomization enabled'
        else:
            output = 'Unknown hash randomization: ' + str(hr)
    except AttributeError:
        output = 'Hash randomization not supported'

    response_headers = [('Content-type', 'text/plain'),
                        ('Content-Length', str(len(output)))]
    start_response(status, response_headers)

    return [output]