在http和https上运行Gunicorn

Tre*_*own 9 django apache2 http-redirect gunicorn

当我启动Gunicorn服务时,我目前使用此命令启动它:

gunicorn --certfile=/Projects/thebodyofchrist.us.crt --keyfile=/Projects/thebodyofchrist.us.key bodyofchrist.wsgi -b 0.0.0.0:443 -b 0.0.0.0:80 -w 10
Run Code Online (Sandbox Code Playgroud)

用于将gunicorn绑定到http和https - 或设置apache2以侦听http并使用现有参数将请求重定向到https.我有数百个链接http://example.com/sample/request ,需要它自动转到https://example.com/sample/request

gunicorn正在主持django.

谢谢你的帮助!

小智 5

Gunicorn是一个非常可靠的项目,我希望他们有朝一日用多个端口绑定和命令行开关来构建它,以表明SSL优先级。

最终投入生产时,您将需要使用Apache或Nginx的出色负载平衡。

但是,没有什么可以阻止您(在开发期间)运行设置了密钥文件和certfile的绑定到端口80的某些工作程序以及绑定到端口443的某些工作程序。然后,您可以在登录后将登录链接写为“绝对” URL,例如href =“ https:// yoursite / login”,他们将使用https url。

#!/bin/sh
# put 8 workers as Daemon listening for HTTPS on 443
gunicorn -D -w 8 --certfile=/Projects/thebodyofchrist.us.crt --keyfile=/Projects/thebodyofchrist.us.key bodyofchrist.wsgi -b 0.0.0.0:443

# put 2 workers as Daemon listening for HTTP on port 80
gunicorn -D -w 2 bodyofchrist.wsgi -b 0.0.0.0:80
Run Code Online (Sandbox Code Playgroud)

  • 现在如何将所有 http 流量重定向到 https? (2认同)

Vla*_*adV 1

可以在gunicorn 内部添加此类支持。就目前而言,这是不可能的。

https://github.com/benoitc/gunicorn/issues/1466