zoukankan      html  css  js  c++  java
  • uWSGI+nginx部署Django项目记录

    一:安装uWSGI

    在/usr/local目录下新建目录:uwsgi,用于存储uWSGI配置文件及日志。配置文件内如如下:

    # mysite_uwsgi.ini file
    [uwsgi]
    # Django-related settings
    # the base directory (full path)
    #指定django的项目目录,第一层
    chdir           = /usr/local/infoOCR
    # Django's wsgi file
    #找到django的wsgi文件
    #这里需要写项目的第二层目录Alibab_crm
    module          = infoOCR.wsgi
    # the virtualenv (full path)
    #填写虚拟环境的绝对路径
    home            = /usr/local/infoOCR/info_env
    # process-related settings
    # master
    master          = true
    # maximum number of worker processes
    processes       = 2
    # the socket (use the full path to be safe
    #指定socket协议,运行django,只能与nginx结合时使用
    socket          = 127.0.0.1:8000
    #如果你没用nginx,只想自己启动一个http界面,用这个
    #http =  0.0.0.0:8001
    
    # ... with appropriate permissions - may be needed
    # chmod-socket    = 664
    # clear environment on exit
    vacuum          = true
    daemonize=/usr/local/uwsgi/uwsgi.log

    如果想让uWSGI也暴露出http,则打开http部分即可。

    启动python的虚拟环境,运行命令安装uWSGI:

    pip install uwsgi

    安装完成后,定位到/usr/local/uwsgi目录,运行命令启动uWSGI:

    uwsgi uwsgi.ini

    启动成功后,可以从浏览器访问8001(前提打开上述配置文件http部分)查看是否正常。

    uWSGI的关闭命令网上一边倒,说:uwsgi --stop uwsgi.pid,但实测不行。只能用以下命令:

    killall  -9 uwsgi
    或者
    pkill -f uwsgi -9

    二:安装nginx

    拷贝nginx-1.20.1.tar.gz到目录:/usr/local,运行命令解压:tar -zxvf nginx-1.20.1.tar.gz,解压后注意不要修改文件夹名称为nginx,因为nginx的编译安装目录就是nginx,这样会与源文件目录冲突。直接进入nginx-1.20.1目录,运行:

    ./configure
    make&&make install

    安装完成后,打开conf/nginx.conf文件,修改配置内容,和uWSGI相互匹配。方法有两种:

    定位到:location /部分:

    方法一:假如uWSGI服务器也开启http,则在location中添加:

    proxy_pass http://127.0.0.1:8001

    即采用http代理方式,转发到uWSGI,但这样失去了使用wsgi协议优势,性能降低不少,不推荐。

    方法二:采用wsgi协议,在location部分添加:

    include /usr/local/nginx/conf/uwsgi_params;
    uwsgi_pass 127.0.0.1:8000

    这样采用wsgi代理方式,性能会更好。

    配置完成后,启动及关闭nginx方法为:

    启动:sbin/nginx

    关闭:sbin/nginx -s stop

    文章出处:www.cnblogs.com/jizhong

    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接。否则保留追究法律责任的权利。

  • 相关阅读:
    IIC/I2C从地址之7位,8位和10位详解
    ARM uxtw
    ARM(CM3)的汇编指令
    WZR/XZR ARM
    LDR r, label 和 LDR r, =label的区别
    Distinguishing between 32-bit and 64-bit A64 instructions
    03JavaScript程序设计修炼之道_2019-06-18_20-39-14_事件onload&onmouseover&out
    02-CSS基础与进阶-day6_2018-09-05-20-18-21
    02-CSS基础与进阶-day5_2018-09-03-22-10-39
    02-CSS基础与进阶-day5_2018-09-03-21-41-57
  • 原文地址:https://www.cnblogs.com/jizhong/p/15167415.html
Copyright © 2011-2022 走看看