django 项目常用开发部署shell脚本

本文详细介绍了一种使用Django REST框架、uwsgi及nginx部署RESTful API的方法,包括数据库初始化、迁移、服务启动及前端静态资源配置等关键步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

假设我的application name 为DjangoRESTImage;

假设我的数据库使用sqlite3;

删除数据库脚本:rm_db.sh

rm -rf db.sqlite3
rm -rf DjangoRESTImage/migrations/

 

python manage.py  启动 run_as_python.sh

python manage.py migrate
python manage.py makemigrations DjangoRESTImage
python manage.py migrate DjangoRESTImage
python manage.py runserver 0.0.0.0:48080

 

uwsgi 启动程序 run_as_server.sh

python manage.py migrate
python manage.py makemigrations DjangoRESTImage
python manage.py migrate DjangoRESTImage
uwsgi --ini ./deploy-file/uwsgi.ini

 

简单uwsgi脚本 uwsgi.ini

[uwsgi]
#the local unix socket file than commnuincate to Nginx
socket = 127.0.0.1:48080
# the base directory (full path)
chdir = /home/dalaoshe/DjangoREST

# Django's wsgi file
wsgi-file = DjangoREST/wsgi.py
# maximum number of worker processes
processes = 4
#thread numbers startched in each worker process
threads = 2
 
#monitor uwsgi status
stats = 127.0.0.1:9191
# clear environment on exit
vacuum          = true

 

[uwsgi]
#the local unix socket file than commnuincate to Nginx

env LANG="zh_CN.UTF-8"
env LANGUAGE="zh_CN.UTF-8"
;env LANG="en_US.UTF-8"
;env LANGUAGE="en_US.UTF-8"
socket = 127.0.0.1:48080
# the base directory (full path)

chdir = /home/home/
# Django's wsgi file
wsgi-file = /home/home/DjangoREST/wsgi.py

;module = DjangoREST.wsgi:application
# maximum number of worker processes
processes = 4
#thread numbers startched in each worker process
threads = 2

#monitor uwsgi status
stats = 127.0.0.1:9191
# clear environment on exit
vacuum          = true
daemonize =/var/log/uwsgi/django_uwsgi_new.log
;logto =/var/log/uwsgi/django_uwsgi.log

 

 

nginx部署配置,包含前端react代码 nginx.conf

user root;
worker_processes auto;
pid /run/nginx.pid;

events {
    worker_connections 1024;
    # multi_accept on;
}

http {
    include /etc/nginx/mime.types;
    default_type  application/octet-stream;

server {

    listen 8080;
    server_name localhost;


    location / {
        root /home/dalaoshe/ant-design-pro/dist;
        index  index.html;
        try_files $uri $uri/ /index.html;
        }

    location /user {
        proxy_pass http://localhost:58080/user;
    }
}

server {
        listen       58080;
        server_name  localhost;

        location / {
            uwsgi_pass  127.0.0.1:48080;
            include uwsgi_params;
            index  index.html index.htm;
            client_max_body_size 35m;
        }
        location /static {
            alias /home/home/DjangoREST/collected_static;
        }
    }

#    include /etc/nginx/conf.d/*.conf;
     include /etc/nginx/sites-enabled/*;
}

 

转载于:https://www.cnblogs.com/adamans/articles/9962785.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值