zoukankan      html  css  js  c++  java
  • 通过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 /root/mxonline/online/conf/mx_nginx.conf /etc/nginx/conf.d/

    重启nginx,这里有坑,路径不是绝对路径,链接无效

    新建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
  • 相关阅读:
    【试水CAS-4.0.3】第07节_CASclient配置单点登录
    30分钟,让你彻底明白Promise原理
    【你离硅谷只差一步】网易中国创业家大赛项目火热征集中
    21分钟学会写编译器
    Android 模拟器下载、编译及调试
    GitLab 自动触发 Jenkins 构建
    微服务监控探索
    感觉要火!妹子实地采访网易猪厂程序员七夕怎么过
    延迟任务调度系统—技术选型与设计(下篇)
    使用QUIC
  • 原文地址:https://www.cnblogs.com/wj5633/p/6676094.html
Copyright © 2011-2022 走看看