我正在尝试将wsgi和asgi应用程序设置为我的nginx服务器的反向代理。这是问题所在。 wsgi应用程序使用gunicorn可以平稳运行,而asgi应用程序则不能。我正在使用daphne作为asgi应用。
这是daphne.service:
[Unit]
Description=daphne daemon
Requires=daphne.socket
After=network.target
[Service]
User=goutam
Group=www-data
WorkingDirectory=/home/goutam/cilliai
ExecStart=/home/goutam/cilliai/venv/bin/daphne -u /run/daphne.sock --access-log - --proxy-headers api.asgi:application
[Install]
WantedBy=multi-user.target
这是daphne.socket:
[Unit]
Description=daphne socket
[Socket]
ListenStream=/run/daphne.sock
[Install]
WantedBy=sockets.target
这是asgi应用程序的nginx conf:
location ~^/(ws) {
proxy_pass http://unix:/run/daphne.sock;
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 https;
}
Gunicorn也具有类似的配置,可以完美运行,但daphne服务则不能。 当我运行时:
sudo systemctl守护程序重新加载 sudo systemctl重新启动daphne
我收到以下错误消息。
19-12-09 02:46:42,737信息在UNIX上启动服务器:/run/daphne.sock
19-12-09 02:46:42,739信息HTTP / 2支持未启用(安装http2和tls Twisted> extras)
19-12-09 02:46:42,739信息配置端点unix:/run/daphne.sock
19-12-09 02:46:42,740严重收听失败:[Errno 13]权限被拒绝:'7441'-> b'/ run / daphne.sock.lock'