在 https 上运行 Gunicorn?
我们有一些通过代理(Apache 和 Nginx)的 Django 设置,最终到达实际的 Django 运行时。
即使 HTTPS 位于我们的网络中,我们也需要端到端的 HTTPS。由于 Gunicorn 在我们其他设置中的成功和性能,我们一直在重新审视它,但需要使用 HTTPS 进行端到端测试以保持一致。
我们的拓扑是这样的:
https://foo.com -> [面向公众的代理]-> (https)-> [内部服务器 https://192...:8001]
如何配置 Gunicorn 来侦听 HTTPS有自签名证书?
We've got a few Django setups that go through a proxy (Apache and Nginx) that eventually make their way to the actual Django runtime.
We need to have HTTPS end to end even once it's in our network. We've been revisiting Gunicorn due to its success and performance in our other setups, but needed to test with HTTPS end to end to be consistent.
Our topology is as such:
https://foo.com -> [Public facing proxy] -> (https) -> [internal server https://192...:8001]
How does one configure Gunicorn to listen on HTTPS with a self signed certificate?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
Gunicorn 现在支持 SSL,自版本 17.0 起。您可以将其配置为侦听 https,如下所示:
如果您使用
--bind
侦听端口 80,请记住将端口更改为 443(HTTPS 连接的默认端口)。例如:Gunicorn now supports SSL, as of version 17.0. You can configure it to listen on https like this:
If you were using
--bind
to listen on port 80, remember to change the port to 443 (the default port for HTTPS connections). For example:回复很晚,但对于遇到此问题的其他人来说,还有另一种选择,使用 nginx 作为上面的“[面向公众的代理]”。
配置 nginx 以处理端口 443 上传入的 SSL 流量,然后将 proxy_pass 发送到内部端口上的 Gunicorn。外部流量是加密的,nginx和gunicorn之间的流量无论如何都不会暴露。我发现这非常容易管理。
Massively late reply, but for anyone else coming across this, there's another option using nginx as the "[Public facing proxy]" above.
Configure nginx to handle the incoming SSL traffic on port 443, and then proxy_pass to gunicorn on an internal port. External traffic is encrypted, and the traffic between nginx and gunicorn isn't exposed anyway. I find this very simple to manage.
如果您使用gunicorn.config.py或类似的gunicorn配置文件,您可以添加证书文件和密钥文件。
配置文件可用于将设置初始化为环境变量,如果您有大量设置,配置文件会很有帮助。
使用配置文件
通过创建名为的文件来创建配置文件
gunicorn.config.py
一些常用的设置是
<预><代码>绑定=“0.0.0.0:8000”
工人 = 4
pidfile = 'pidfile'
错误日志 = '错误日志'
日志级别 = '信息'
访问日志='访问日志'
access_log_format = '%(h)s %(l)s %(u)s %(t)s "%(r)s" %(s)s %(b)s "%(f)s" "%(作为”'
当然
文档和配置文件< a href="https://github.com/benoitc/gunicorn/blob/master/examples/example_config.py" rel="noreferrer">示例
这些设置运行gunicorn
使用
If you're using a gunicorn.config.py or similar gunicorn config file you can add the certificate file and key file.
Config files can be used to initialise settings as env variables and can be helpful if you had lots of settings.
To use config file
Create a config file by creating a file named
gunicorn.config.py
Some usual settings would be
and of course
Check out the documentation and a config file example
to run gunicorn with these settings
since
除了
certfile
和keyfile
之外,您还需要添加ca-certs
。在没有通过ca-certs
的情况下,我在Android设备上获得了未找到证书路径的信任锚。
。命令示例:
In addition to
certfile
andkeyfile
you need to addca-certs
as well. Without passingca-certs
, I was gettingTrust anchor for certification path not found.
on Android devices.Sample command: