设置gunicorn与Django一起运行

时间:2016-12-29 07:20:18

标签: python django gunicorn

当我进入kb并运行kb时,我已经安装了gunicorn和我的django项目gunicorn --bind 0.0.0.0:8000 kb.wsgi:application,它运行正常。

我在/etc/init/gunicorn.conf

上运行nano
description "Gunicorn application server handling myproject"

start on runlevel [2345]
stop on runlevel [!2345]


respawn
setuid user
setgid www-data
chdir /home/ubuntu/kb

exec gunicorn --workers 3 --bind unix:/home/ubuntu/kb/kb.sock kb.wsgi:application

当我运行sudo service gunicorn start

我得到Failed to start gunicorn.service: Unit gunicorn.service not found.

更新

执行官:

exec gunicorn --workers 3 --bind unix:/home/ubuntu/kb/kb.sock kb.wsgi:application

来自一个示例,其中gunicorn安装在virtualenv中。我已将exec virtualenv\bin\gunicorn修改为exec gunicorn

1 个答案:

答案 0 :(得分:0)

而不是使用gunicorn.conf更好地使用下面的文件....

sudo nano /etc/systemd/system/gunicorn.service

在此文件中添加以下conf设置....

[Unit]
Description=gunicorn daemon
After=network.target

[Service]
User=dj
Group=www-data
WorkingDirectory=/home/dj/myproject
ExecStart=/home/dj/myproject/myprojectenv/bin/gunicorn --access-logfile - --workers 3 --bind unix:/home/dj/myproject/myproject.sock myproject.wsgi:app$

[Install]
WantedBy=multi-user.target

更改目录的权限..

chmod g + x / home / dj /

chmod g + r / home / dj /

sudo chgrp www-data / home / dj /

注意:请确保gunicorn应该在virtualenv ..

仅供参考:pip install gunicorn 在virtualenv

希望这对你有所帮助.. 它为我工作..

相关问题