Ary*_*rog 22

要在conf.py文件中更改"Server:"http标头,请执行以下操作:

 import gunicorn
 gunicorn.SERVER_SOFTWARE = 'Microsoft-IIS/6.0'
Run Code Online (Sandbox Code Playgroud)

并使用沿线的调用 gunicorn -c conf.py wsgi:app

要完全删除标题,你可以通过用过滤掉标题的子类替换它的http响应类来修补gunicorn.这可能是无害的,但可能不推荐.将以下内容放在conf.py中:

from gunicorn.http import wsgi

class Response(wsgi.Response):
    def default_headers(self, *args, **kwargs):
        headers = super(Response, self).default_headers(*args, **kwargs)
        return [h for h in headers if not h.startswith('Server:')]

wsgi.Response = Response
Run Code Online (Sandbox Code Playgroud)

用gunicorn测试18


Pas*_*iot 8

这里还没有明确写出来,所以我要确认最新版本的 Gunicorn (20.1.x) 的最简单方法是将以下行添加到配置文件中:

import gunicorn 
gunicorn.SERVER = 'undisclosed'
Run Code Online (Sandbox Code Playgroud)


viv*_*d4v 5

gunicorn.conf.py对于较新版本 (20.0.4):在运行命令的目录中创建一个包含以下内容的文件gunicorn

import gunicorn
gunicorn.SERVER_SOFTWARE = 'My WebServer'
Run Code Online (Sandbox Code Playgroud)

  • 对于gunicorn >= 20.1.0,您需要将变量重命名为gunicorn.SERVER。 (2认同)

Vro*_*roo 1

您可以编辑 __init__.py 将 SERVER_SOFTWARE 设置为您想要的任何内容。但我真的很希望能够通过标志禁用此功能,这样我在升级时就不需要重新应用补丁。