スーパーバイザー システムでセットアップしようとしているときに問題に直面する Django チャネルを使用して Web アプリケーションを作成しました。
まず、アプリケーションはローカルでうまく機能します。
リモートで (私は Ubuntu Server 18.04 LTS で AWS EC2 インスタンスを使用しています)、コマンドdaphne -b 0.0.0.0 -p 8000 mysite.asgi:application
で実行するとうまく動作します。
ただし、Supervisor で動作させることはできません。私は公式の Django Channels ドキュメント ( https://channels.readthedocs.io/en/latest/deploying.html )の指示に従います。
nginx 設定ファイル:
upstream channels-backend { server localhost:8000; } server { server_name www.example.com; keepalive_timeout 5; client_max_body_size 1m; access_log /home/ubuntu/django_app/logs/nginx-access.log; error_log /home/ubuntu/django_app/logs/nginx-error.log; location /static/ { alias /home/ubuntu/django_app/mysite/staticfiles/; } 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; } listen 443 ssl; # managed by Certbot ssl_certificate /etc/letsencrypt/live/www.example.com/fullchain.pem; # managed by Certbot ssl_certificate_key /etc/letsencrypt/live/www.example.com/privkey.pem; # managed by Certbot include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot } server { listen 80; server_name www.example.com; if ($host = www.example.com) { return 301 https://$host$request_uri; } # managed by Certbot return 404; # managed by Certbot }
スーパーバイザー構成ファイル:
[fcgi-program:asgi] socket=tcp://localhost:8000 directory=/home/ubuntu/django_app/mysite command=/home/ubuntu/django_app/venv/bin/daphne -u /run/daphne/daphne%(process_num)d.sock --fd 0 --access-log - --proxy-headers mysite.asgi:application numprocs=4 process_name=asgi%(process_num)d autostart=true autorestart=true stdout_logfile=/home/ubuntu/django_app/logs/supervisor_log.log redirect_stderr=true
このように設定すると、Web ページは機能しません (504 ゲートウェイ タイムアウト)。スーパーバイザーのログ ファイルには次のように表示されます。
2018-11-14 14:48:21,511 INFO Starting server at fd:fileno=0, unix:/run/daphne/daphne0.sock
2018-11-14 14:48:21,516 INFO HTTP/2 support enabled
2018-11-14 14:48:21,517 INFO Configuring endpoint fd:fileno=0
2018-11-14 14:48:22,015 INFO Listening on TCP address 127.0.0.1:8000
2018-11-14 14:48:22,025 INFO Configuring endpoint unix:/run/daphne/daphne0.sock
2018-11-14 14:48:22,026 CRITICAL Listen failure: [Errno 2] No such file or directory: '1416' -> b'/run/daphne/daphne0.sock.lock'
2018-11-14 14:48:22,091 INFO Starting server at fd:fileno=0, unix:/run/daphne/daphne2.sock
2018-11-14 14:48:22,096 INFO HTTP/2 support enabled
2018-11-14 14:48:22,097 INFO Configuring endpoint fd:fileno=0
2018-11-14 14:48:22,135 INFO Starting server at fd:fileno=0, unix:/run/daphne/daphne3.sock
2018-11-14 14:48:22,152 INFO HTTP/2 support enabled
2018-11-14 14:48:22,153 INFO Configuring endpoint fd:fileno=0
2018-11-14 14:48:22,237 INFO Listening on TCP address 127.0.0.1:8000
2018-11-14 14:48:22,241 INFO Listening on TCP address 127.0.0.1:8000
2018-11-14 14:48:22,242 INFO Configuring endpoint unix:/run/daphne/daphne3.sock
2018-11-14 14:48:22,242 CRITICAL Listen failure: [Errno 2] No such file or directory: '1419' -> b'/run/daphne/daphne3.sock.lock'
2018-11-14 14:48:22,252 INFO Configuring endpoint unix:/run/daphne/daphne2.sock
2018-11-14 14:48:22,252 CRITICAL Listen failure: [Errno 2] No such file or directory: '1420' -> b'/run/daphne/daphne2.sock.lock'
等
スーパーバイザー コマンドでは、以前に実行した方法とは別の方法で (他のパラメーター セットを使用して) Daphne プロセスが呼び出されることに注意してください。アドレスとポートのパラメーターの代わりに、ソケットとファイル記述子のパラメーターがあります (これについては説明しません)よく知っている)。発生したエラーの理由であると思われます。
どんな助けや提案も高く評価されます。
関連するパッケージのバージョン:
channels==2.1.2
channels-redis==2.2.1
daphne==2.2.1
Django==2.1.2
編集:
ソケットファイル用の空のファイルを作成すると(スーパーバイザー構成ファイルの Daphne のコマンドに存在します)、つまり. /run/daphne/daphne0.sock
、/run/daphne/daphne1.sock
などの場合、ログ ファイルには次のように記載されています。
2018-11-15 10:24:38,289 INFO Starting server at fd:fileno=0, unix:/run/daphne/daphne0.sock
2018-11-15 10:24:38,290 INFO HTTP/2 support enabled
2018-11-15 10:24:38,280 INFO Configuring endpoint fd:fileno=0
2018-11-15 10:24:38,458 INFO Listening on TCP address 127.0.0.1:8000
2018-11-15 10:24:38,475 INFO Configuring endpoint unix:/run/daphne/daphne0.sock
2018-11-15 10:24:38,476 CRITICAL Listen failure: Couldn't listen on any:b'/run/daphne/daphne0.sock': [Errno 98] Address already in use.
質問: これらのファイルは空であってはなりませんか? 何を含めるべきですか?