Ubuntu + Nginx + uwsgi部署Django Web项目

项目树状图

shop                                                                                                                                                                   
├── db.sqlite3                                                                                                                                                         
├── dump.sql                                                                                                                                                           
├── mallApp                                                                                                                                                            
│   ├── admin.py                                                                                                                                                       
│   ├── apps.py                                                                                                                                                        
│   ├── __init__.py                                                                                                                                                    
│   ├── migrations                                                                                                                                                     
│   ├── models.py                                                                                                                                                      
│   ├── urls                                                                                                                                                           
│   │   ├── urls_cart.py                                                                                                                                               
│   │   ├── urls_goods.py                                                                                                                                              
│   │   ├── urls_order.py                                                                                                                                              
│   │   ├── urls_person.py                                                                                                                                             
│   │   └── urls_user.py                                                                                                                                               
│   └── views                                                                                                                                                          
│       ├── accounts_forms.py                                                                                                                                          
│       ├── view_bill.py                                                                                                                                               
│       ├── view_cart.py                                                                                                                                               
│       ├── view_goods.py                                                                                                                                              
│       ├── view_order.py                                                                                                                                              
│       ├── view_person.py                                                                                                                                             
│       └── view_user.py                                                                                                                                               
├── manage.py                                                                                                                                                          
├── shop                                                                                                                                                               
│   ├── __init__.py                                                                                                                                                    
│   ├── settings.py                                                                                                                                                    
│   ├── urls.py                                                                                                                                                        
│   └── wsgi.py                                                                                                                                                        
├── static                                                                                                                                                             
├── templates                                                                                                                                                          
└── uwsgi.ini

 

1. 安装Nginx

sudo apt install nginx -y

2. 安装uwsgi

pip3 install uwsgi

#  如果没有pip3,可以通过以下命令安装
sudo apt install python3-pip -y

3. 编辑文件uwsgi.ini

[uwsgi]                                                                                                                                                                
chdir=/home/zl/shop/                                                                                                                                                                                                                                                                                           
file=shop/wsgi.py                                                                                                                                    
socket=127.0.0.1:8090                                                                                                                                                  
workers=5                                                                                                                                                                  
uid=root                                                                                                                                                               
gid=root                                                                                                                                                               
                                                                                                                                                                       
master=true                                                                                                                                                            
# 自动移除unix Socket和pid文件当服务停止的时候                                                                                                                         
vacuum=true                                                                                                                                                            
# 序列化接受的内容,如果可能的话                                                                                                                                       
thunder-lock=true                                                                                                                                                      
# 启用线程                                                                                                                                                             
enable-threads=true                                                                                                                                                    
# 设置自中断时间                                                                                                                                                       
harakiri=30                                                                                                                                                            
# 设置缓冲                                                                                                                                                             
post-buffering=4096

4. 配置nginx(在/etc/nginx/sites-enabled下新建shop文件)

server {                                                                                                                                                               
    listen 80;                                                                                                                                                         
    server_name b.jaja.cc;                                                                                                                                             
    root /home/zl/nginx;                                                                                                                                               
    index index.php index.html index.htm index.nginx-debian.html;                                                                                                      
    location / {                                                                                                                                                       
        include uwsgi_params;                                                                                                                                          
        uwsgi_pass 127.0.0.1:8090;                                                                                                                                                              
    }                                                                                                                                                                  
    location /static/ {                                                                                                                                                
        expires 30d;                                                                                                                                                   
        autoindex off;                                                                                                                                                 
        add_header Cache-Control private;                                                                                                                              
    }                                                                                                                                                                  
}

5. 查看nginx服务器状态,启动或重启nginx

sudo service nginx start/restart

6. 进入项目根目录通过uwsgi启动项目

sudo uwsgi uwsgi.ini

 

你可能感兴趣的:(Ubuntu + Nginx + uwsgi部署Django Web项目)