django - 使用 Daphne 和 Nginx 部署 django 频道的问题
问题描述
我在尝试打开网站时收到 502 错误。我使用了官方网站 链接中的说明
在/etc/supervisor/conf.d/添加了新文件 lifeline.conf
生命线配置文件
[fcgi-program:asgi]
# TCP socket used by Nginx backend upstream
socket=tcp://localhost:8000
# Directory where your site's project files are located
directory=/home/ubuntu/lifeline/lifeline-backend
# Each process needs to have a separate socket file, so we use process_num
# Make sure to update "mysite.asgi" to match your project name
command=/home/ubuntu/Env/lifeline/bin/daphne -u /run/daphne/daphne%(process_num)d.sock --fd 0 --access-log - --proxy-head$
# Number of processes to startup, roughly the number of CPUs you have
numprocs=4
# Give each process a unique name so they can be told apart
process_name=asgi%(process_num)d
# Automatically start and recover processes
autostart=true
autorestart=true
# Choose where you want your log to go
stdout_logfile=/home/ubuntu/asgi.log
redirect_stderr=true
设置 nginx 配置
upstream channels-backend {
server localhost:8000;
}
server {
listen 80;
server_name staging.mysite.com www.staging.mysite.com;
client_max_body_size 30M;
location = /favicon.ico { access_log off; log_not_found off; }
location / {
try_files $uri @proxy_to_app;
}
location @proxy_to_app {
proxy_pass http://channels-backend;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
}
}
我检查了 asgi 日志文件,它包含一个错误。
daphne: error: the following arguments are required: application
我猜在lifeline.conf中有一个错误。
解决方案
我假设您没有将 asgi 应用程序传递给 daphne,因为您粘贴的配置有问题。你必须正确地通过它。假设你有一个包含 asgi 应用程序实例package
的模块,你必须这样做asgi.py
command=/home/ubuntu/Env/lifeline/bin/daphne -u /run/daphne/daphne%(process_num)d.sock conf.asgi:application
conf.asgi:application
应该在最后。
推荐阅读
- timer - Arduino 的 micros() 方法需要 500 多个周期才能在 Nano 33 BLE Sense 上执行
- python - Django内联表单集不保存默认值
- reactjs - 每个应用实例仅调用一次 React useEffect
- python - 如何在烧瓶中播放上传的音频文件
- amazon-web-services - 在 EMR 上设置 Apache Sedona
- python - 如何在字典中添加新条目?
- node.js - 文件名包含括号时的 AWS S3 CLI 错误
- c# - 使自定义 msbuild 任务依赖于 nuget 的可执行文件
- python-3.x - 如何在bash脚本中用空格循环名称?
- python - 有效地找到排序的 2D Numpy 数组中的所有点