So far, I've used Gunicorn, with this configuration file 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
And Nginx proxy requests for this unix socket.
Trying Daphne, I realized that I can not specify --env DJANGO_SETTINGS_MODULE='config.settings.production'
But I specify this variable in asgi.py
, on it all is normal.
As soon as I ran the gunicorn service
, the socket itself was instantly created on which requests from nginx
.
When I try to do the same trick with Daphne, I get an error:
Jun 26 11:48:32 p435061.kvmvps daphne[8447]: ValueError: invalid literal for int() with base 8: '/var/www/user/user.sock'
But I can not figure out how to use the unix.sock
when I try to run Daphne
and create my systemd
file
UPDATE
I changed the settings file, and it gives something strange, but it works:
[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 returns:
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
But nginx swears at the lack of a *.sock file:
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"
I spent the whole day fighting this, but nothing happened.
The answer was quite simple:
The problem was that I pointed out -b unix:
, and the unix:
prefix interfered with the work, and, of course, the flag should be set -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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With