nginx+uwsgi部署django的简单介绍-第二版

1.部署django项目

1.1. 根据django项目中setting.py文件,安装对应的django版本,防止代码运行不起来。

1.2.django所需的python环境 最好由anaconda新建的虚拟环境来进行部署且不能是root用户,建议建一个新用户,不然后期uwsgi的安装环境会有问题

1.3.安装好运行python manage.py runserver 0.0.0.0:8001 浏览器访问正常,说明django部署好了

 

2.部署uwsgi

1.1 在python的虚拟环境中安装uwsgi  运行pip install uwsgi可能报错;运行conda install uwsgi安装成功

1.2.在manage.py同级目录下,新建uwsgi.ini文件

[uwsgi]
socket = 0.0.0.0:8001 
processes = 2
threads = 4
enable-threads=true
lazy-apps=true  
uid = nginx
gid = nginx
chmod-socket=644 
master=true 
chdir = /tmp/mychatgpt
module = mychatgpt.wsgi
home = /home/download/anaconda3/envs/myenv39 
vhost = true  
reload-mercy = 10
vacuum = true
max-requests = 1000
;limit-as = 65536  ;程序需要的内存过大,会导致uwsgi内存不停的错误
buffer-size = 655536 
pidfile =   /home/download/mychatgpt/uwsgi.pid
;daemonize = /home/download/mychatgpt/uwsgi.log

1.3.编写好后,运行uwsgi --ini uwsgi.ini 浏览器如果可以访问正常,则uwsgi部署完成

 

3.安装nginx

3.1.安装nginx

 yum -y install gcc automake autoconf libtool make
 yum install gcc gcc-c++ 
 sudo apt-get update
 sudo yum install nginx

3.2.配置nginx.conf

server {
    listen 8888;
    server_name localhost;
    location / { 
        include /etc/nginx/uwsgi_params; 
        uwsgi_pass 127.0.0.1:8001;
    }
}

3.3.启动、停止

systemctl status nginx.service
systemctl stop nginx.service
systemctl start nginx.service

 

4.至此全部部署完成,访问127.0.0.1:8888即可访问所部署的项目,注意uwsgi以及nginx是必须要要开启的。

 

posted @ 2023-03-24 10:36  lingwang3  阅读(35)  评论(0编辑  收藏  举报