标签:nginx django gunicorn django-channels daphne
我有一个django项目,最近添加了使用websockets的渠道.这似乎一切正常,但我遇到的问题是准备好生产.
我的设置如下:
Nginx web server
Gunicorn for django
SSL enabled
因为我已经为混音添加了频道.我花了最后一天试图让它发挥作用.
在所有turtotials他们说你在某个端口上运行daphne然后显示如何为此设置nginx.
但是如果有枪支服务django呢?
所以现在我有guncorn在8001上运行这个django应用程序
如果我在另一个端口上运行daphne,那么就说8002 – 它应该如何知道这个django项目的标准?跑步工人怎么样?
Gunicorn,Daphne和跑步者都应该一起跑吗?
解决方法:
这个问题实际上是在最新的Django Channels docs中解决的:
It is good practice to use a common path prefix like /ws/ to
distinguish WebSocket connections from ordinary HTTP connections
because it will make deploying Channels to a production environment in
certain configurations easier.In particular for large sites it will be possible to configure a
production-grade HTTP server like nginx to route requests based on
path to either (1) a production-grade WSGI server like Gunicorn+Django
for ordinary HTTP requests or (2) a production-grade ASGI server like
Daphne+Channels for WebSocket requests.Note that for smaller sites you can use a simpler deployment strategy
where Daphne serves all requests – HTTP and WebSocket – rather than
having a separate WSGI server. In this deployment configuration no
common path prefix like is /ws/ is necessary.
在实践中,您的NGINX配置看起来像(缩写为仅包含相关位):
upstream daphne_server {
server unix:/var/www/html/env/run/daphne.sock fail_timeout=0;
}
upstream gunicorn_server {
server unix:/var/www/html/env/run/gunicorn.sock fail_timeout=0;
}
server {
listen 80;
server_name _;
location /ws/ {
proxy_pass http://daphne_server;
}
location / {
proxy_pass http://gunicorn_server;
}
}
(上面假设您将Gunicorn和Daphne服务器绑定到Unix套接字文件.)
标签:nginx,django,gunicorn,django-channels,daphne 来源: https://codeday.me/bug/20190522/1153697.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。