设置gunicorn与Djang一起运行

2024-04-20 09:09:17 发布

您现在位置:Python中文网/ 问答频道 /正文

我已经安装了gunicorn和我的django项目kb,当我cd到kb并运行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.

更新

执行行:

^{pr2}$

来自一个在virtualenv中安装gunicorn的例子。我已经把exec virtualenv\bin\gunicorn编辑成exec gunicorn


Tags: 项目djangowsgihomekbvirtualenvapplicationbind
1条回答
网友
1楼 · 发布于 2024-04-20 09:09:17

而不是使用古尼康.conf最好使用下面的文件。。。。在

sudo nano/etc/systemd/system公司/gunicorn服务

在这个文件中添加下面的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/主页/dj/

chmod g+r/主页/dj/

sudo chgrp www data/home/dj/

注意:请确保gunicorn应该在virtualenv中。。在

仅供参考:pip在virtualenv下安装gunicorn

希望这对你有帮助。。 它对我有用。。在

相关问题 更多 >