通过nginx+uwsgi部署django应用

Posted 兔头咖啡

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了通过nginx+uwsgi部署django应用相关的知识,希望对你有一定的参考价值。

上传应用

# 创建虚拟环境
pyenv virtualenv online

# 进入工程目录,安装包
pip install -r requirements.txt

#测试
python manage,py runserver

访问httP://ip:8000

安装uwsgi

1 # 进入虚拟环境
2 pyenv activate online
3 
4 pip install uwsgi
5 
6 # 测试uwsgi
7 uwsgi –http :8000 –module online.wsgi

访问httP://ip:8000

安装nginx

1 yum install nginx

新建mx_nginx.conf

upstream django {
server 127.0.0.1:8000; # for a web port socket (we‘ll use this first)
}

server {
    # the port your site will be served on
    listen      80;
    # the domain name it will serve for
    server_name 47.92.37.14 www.54noob.top 54noob.top; #\填你的域名或ip
    charset     utf-8;

    access_log /root/mxonline/logs/access.log;
    error_log /root/mxonline/logs/error.log;

    # max upload size
    client_max_body_size 75M;   # adjust to taste
    # Finally, send all non-media requests to the Django server.
    location / {
        uwsgi_pass  django; #一定要跟uwsgi配置的一样
        include     uwsgi_params; # the uwsgi_params file you installed
        uwsgi_param UWSGI_SCRIPT online.wsgi;  #入口文件,即wsgi.py录的位置
        uwsgi_param UWSGI_CHDIR /root/mxonline/online;       #项目根目录
    }
    access_log off;
}

加入nginx配置

1 ln -s conf/mx_nginx.conf /etc/nginx/conf.d/

重启nginx 或者nginx -t 、nginx -s reload

新建mx_uwsgi.ini

1 [uwsgi]
2 
3 chdir = /root/mxonline/online    #工程目录
4 module = online.wsgi        #wsgi.py
5 master = true
6 processes = 10
7 socket = 127.0.0.1:8000    #nginx配置对应
8 vacuum = true
9 virtualenv = /root/.pyenv/versions/online  #虚拟环境

启动项目

nginx     #启动nginx
/usr/local/redis/bin/redis-server /usr/local/redis/etc/redis.conf   #启动redis

pyenv activate online  #进入虚拟环境
cd ~/online  #进入工程目录

uwsgi -i conf/uwsgi.ini &    #启动uwsgi

celery -A online worker -l info  #启动celery

 

以上是关于通过nginx+uwsgi部署django应用的主要内容,如果未能解决你的问题,请参考以下文章

centos7 下通过nginx+uwsgi部署django应用

nginx+django+uwsgi部署配置

Ubuntu18部署uwsgi+flask应用

Django3.0 + nginx + uwsgi 部署

[部署开发环境]部署django的生成环境nginx+uwsgi+django

Django+Nginx+uWSGI部署