私は本番環境で django-channels2+daphne を使用しています。不確実な時間が経過した後、このエラーが 2 回 (2 時間後と 6 時間後に) 発生504
し、HTTP 要求に対する応答が含まれていました。問題をどのようにデバッグすればよいかわかりません。nginx、django-channels2、daphne を使用。
Application instance <Task pending coro=<AsgiHandler.__call__() running at /usr/local/lib/python3.7/site-packages/channels/http.py:202> wait_for=<Future pending cb=[_chain_future.<locals>._call_check_cancel() at /usr/local/lib/python3.7/asyncio/futures.py:348, <TaskWakeupMethWrapper object at 0x7ff116ef9708>()]>> for connection <WebRequest at 0x7ff116a86d30 method=GET uri=/api/v1/feed/?page_size=10&distance=-1000¬_reviewed=1 clientproto=HTTP/1.1> took too long to shut down and was killed
これが私のnginx構成です:
server {
server_name www.example.com example.com;
return 301 https://example.com$request_uri;
}
server {
server_name www.lvh.me lvh.me;
return 301 https://lvh.me$request_uri;
}
server {
listen 443 ssl;
ssl_certificate /etc/ssl/certs/server.crt;
ssl_certificate_key /etc/ssl/private/server.key;
server_name www.example.com;
return 301 https://example.com$request_uri;
}
server {
listen 443 ssl;
ssl_certificate /etc/ssl/certs/server.crt;
ssl_certificate_key /etc/ssl/private/server.key;
server_name www.lvh.me;
return 301 https://lvh.me$request_uri;
}
server {
server_name example.com lvh.me;
charset UTF-8;
listen 443 ssl;
ssl_certificate /etc/ssl/certs/server.crt;
ssl_certificate_key /etc/ssl/private/server.key;
access_log /var/log/nginx/mini.access.log;
error_log /var/log/nginx/mini.error.log;
location /static/ {
autoindex on;
root /data/django;
}
location /media/ {
autoindex on;
root /data/django;
}
location / {
proxy_pass http://django:8000;
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;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
daphne.com を次のように開始します。
daphne -b 0.0.0.0 -p 8000 project.asgi:application