到目前为止,我使用过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 socket。
当我尝试使用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'
但是我不知道如何在尝试运行Daphne
和创建我的systemd
文件时使用unix.sock
更新
我更改了设置文件,获得了一些奇怪的东西,但它可以工作:
[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"
我花了一整天的时间在这个问题上,但什么都没有发生。
-u <path to socke>
而不是-b <path to sock>
。 - Zada Zorg