到目前为止,我用过Gunicorn ,使用此配置文件 systemd:
[Unit]
Description=gunicorn daemon
After=network.target
[Service]
EnvironmentFile=/var/www/user/.envvars
User=user
Group=www-data
WorkingDirectory=/var/www/user
ExecStart=/var/www/venv/bin/gunicorn --workers 3 --bind unix:/var/www/user/user.sock config.wsgi:application --env DJANGO_SETTINGS_MODULE='config.settings.production'
[Install]
WantedBy=multi-user.target
和Nginx对此 Unix 套接字的代理请求。
尝试Daphne ,我意识到我不能指定
--env DJANGO_SETTINGS_MODULE='config.settings.production'
但是我在
asgi.py
中指定了这个变量,就这一切都是正常的。我一运行
gunicorn service
,套接字本身立即被创建,来自 nginx
的请求.当我尝试对 Daphne 做同样的事情时,我得到一个错误:
Jun 26 11:48:32 p435061.kvmvps daphne[8447]: ValueError: invalid literal for int() with base 8: '/var/www/user/user.sock'
但我不知道如何使用
unix.sock
当我尝试运行 Daphne
并创建我的systemd
文件更新
我更改了设置文件,它给出了一些奇怪的东西,但它有效:
[Unit]
Description=daphne daemon
After=network.target
[Service]
EnvironmentFile=/var/www/gglobal/.envvars
User=gglobal
Group=www-data
WorkingDirectory=/var/www/gglobal
ExecStart=/var/www/venv/bin/daphne -b unix:/var/www/gglobal/gglobal.sock config.asgi:channel_layer -v2
[Install]
WantedBy=multi-user.target
systemctl status daphne 返回:
Jun 26 17:53:46 p435061.kvmvps daphne[14183]: 2017-06-26 17:53:46,722 DEBUG get 'RDS_HOSTNAME' casted as 'None' with default '<NoValue>'
Jun 26 17:53:46 p435061.kvmvps daphne[14183]: 2017-06-26 17:53:46,722 DEBUG get 'RDS_PORT' casted as 'None' with default '<NoValue>'
Jun 26 17:53:46 p435061.kvmvps daphne[14183]: 2017-06-26 17:53:46,722 DEBUG get 'REDIS_ENDPOINT_ADDRESS' casted as 'None' with default '<NoValue>'
Jun 26 17:53:46 p435061.kvmvps daphne[14183]: 2017-06-26 17:53:46,722 DEBUG get 'REDIS_PORT' casted as 'None' with default '<NoValue>'
Jun 26 17:53:46 p435061.kvmvps daphne[14183]: 2017-06-26 17:53:46,723 DEBUG get 'DJANGO_SENTRY_DSN' casted as 'None' with default 'https://56bb387ee6ef4e7b
Jun 26 17:53:46 p435061.kvmvps daphne[14183]: 2017-06-26 17:53:46,723 DEBUG get 'DJANGO_SENTRY_CLIENT' casted as 'None' with default 'raven.contrib.django.
Jun 26 17:53:46 p435061.kvmvps daphne[14183]: 2017-06-26 17:53:46,723 DEBUG get 'DJANGO_SENTRY_LOG_LEVEL' casted as '<class 'int'>' with default '20'
Jun 26 17:53:46 p435061.kvmvps daphne[14183]: 2017-06-26 17:53:46,724 DEBUG get 'DJANGO_SENTRY_LOG_LEVEL' casted as '<class 'int'>' with default '20'
Jun 26 17:53:46 p435061.kvmvps daphne[14183]: 2017-06-26 17:53:46,724 DEBUG get 'DJANGO_ADMIN_URL' casted as 'None' with default '<NoValue>'
Jun 26 17:53:48 p435061.kvmvps daphne[14183]: DEBUG 2017-06-26 17:53:48,186 base 14183 140286354425600 Configuring Raven for host: <raven.conf.remote.RemoteCo
但是 nginx 发誓缺少 *.sock 文件:
2017/06/26 17:47:51 [crit] 12682#12682: *59 connect() to unix:/var/www/project/project.sock failed (2: No such file or directory) while connecting to upstream, client: 5.152.1.201, server: mydomain.com, request: "GET / HTTP/2.0", upstream: "http://unix:/var/www/project/project.sock:/", host: "mydomain.com"
我花了一整天的时间来解决这个问题,但什么也没发生。
最佳答案
答案很简单:
问题是我指出 -b unix:
,以及 unix:
前缀干扰了工作,当然,应该设置标志-u
[Unit]
Description=daphne daemon
After=network.target
[Service]
EnvironmentFile=/var/www/gglobal/.envvars
User=gglobal
Group=www-data
WorkingDirectory=/var/www/gglobal
ExecStart=/var/www/venv/bin/daphne -u /var/www/gglobal/gglobal.sock config.asgi:channel_layer -v2
[Install]
WantedBy=multi-user.target
关于django - 如何在 unix 套接字上绑定(bind) Daphne?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44756294/