当我启动 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
用于将gunicorn绑定(bind)到http和https——或者设置apache2来监听http并使用现有参数将请求重定向到https。
我有数百个指向 http://example.com/sample/request
的链接
并需要它自动转到 https://example.com/sample/request
gunicorn 正在托管 django。
感谢您的帮助!
最佳答案
Gunicorn 是一个非常可靠的项目,我希望他们有一天能够通过多个端口绑定(bind)和命令行开关来指示 SSL 优先级来构建它。
当您最终投入生产时,您将需要使用 Apache 或 Nginx 的卓越负载平衡。
但是没有什么可以阻止您(在开发期间)运行一些绑定(bind)到端口 80 的工作程序和一些绑定(bind)到端口 443 并设置了 key 文件和证书文件的工作程序。然后,您可以将登录链接编写为“绝对”网址,例如href="https://yoursite/login"登录后,他们将使用 https 网址。
#!/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
关于django - 在 http 和 https 上运行 Gunicorn,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35578989/