Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/345.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用gunicorn和NGINX发布Django项目_Python_Django_Sockets_Nginx_Gunicorn - Fatal编程技术网

Python 使用gunicorn和NGINX发布Django项目

Python 使用gunicorn和NGINX发布Django项目,python,django,sockets,nginx,gunicorn,Python,Django,Sockets,Nginx,Gunicorn,我正试图用NGINX和gunicorn发布我的Django项目,但是gunicorn拒绝了我的许可 我的最后一步是我所做的 mkdir /home/sama/websites cd /home/sama/websites mkdir test_project cd test_project 为此项目创建虚拟环境 virtualenv--python=/usr/bin/python3.8venv 虚拟设备激活 source-venv/bin/activate Gunicorn&Django安装

我正试图用NGINX和gunicorn发布我的Django项目,但是gunicorn拒绝了我的许可

我的最后一步是我所做的

mkdir /home/sama/websites
cd /home/sama/websites
mkdir test_project
cd test_project
为此项目创建虚拟环境
virtualenv--python=/usr/bin/python3.8venv

虚拟设备激活
source-venv/bin/activate

Gunicorn&Django安装

pip3 install gunicorn
pip3 install django
创建项目

cd ..
django-admin startproject config test_project
允许防火墙连接到端口8000
sudo ufw允许8000

运行第一个测试
python manage.py运行服务器0.0.0.0:8000

在webbrowser上打开我的服务器ip myIP:8000 我可以看到Django基本页面

停止服务器 CTRL+C

testGunicorn
gunicorn--bind 0.0.0.0:8000 config.wsgi

网络浏览器的测试增益 我再次看到了Djangos页面

服务器停止 CTRL+C

退出虚拟环境
停用

配置Gunicorn 在中创建2个文件 /etc/systemd/system/

gunicorn.socket和gunicorn.service

编辑此文件
sudo nano/etc/systemd/system/gunicorn\u test\u project.socket

/etc/systemd/system/gunicorn.socket
[Unit]
Description=gunicorn daemon

[Socket]
ListenStream=/run/gunicorn.sock

[Install]
WantedBy=sockets.target
测试插座

sudo systemctl start gunicorn.socket
sudo systemctl enable gunicorn.socket
systemlink已创建,请检查它
file/run/gunicorn.sock
输出:/run/gunicorn.sock:socket

curl--unix socket/run/gunicorn.sock localhost

现在我的许可被拒绝了


我已经将文件夹test_项目的权限设置为user sama和group www data,但没有任何效果。怎么了?

我看不出有什么好的理由在这里使用systemd套接字激活

只需使用服务文件并将Gunicorn绑定到HTTP

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

[Service]
User=sama
Group=www-data
WorkingDirectory=/home/sama/websites/test_project
ExecStart=/home/sama/websites/test_project/venv/bin/gunicorn --access-logfile - --workers 3 --bind 0.0.0.0:8000 config.wsgi:application

[Install]
WantedBy=multi-user.target

谢谢,这很有效。但我还有第二个问题。这是我的NGINX文件
listen80;听[:]:80;服务器名称我的秘密域名;location=/favicon.ico{access_log off;log_not_found off;}location/static/{root/home/sama/websites/test_project;}location/{include proxy_params;proxy_passhttp://unix:/run/gunicorn.sock}
但是我不能通过浏览器访问域,但是当我键入subdomain时我可以访问。我没有配置任何子域,这是另一个问题;请这样问。
[Unit]
Description=gunicorn daemon
After=network.target

[Service]
User=sama
Group=www-data
WorkingDirectory=/home/sama/websites/test_project
ExecStart=/home/sama/websites/test_project/venv/bin/gunicorn --access-logfile - --workers 3 --bind 0.0.0.0:8000 config.wsgi:application

[Install]
WantedBy=multi-user.target