• nginx+uwsgi环境部署


    WSGI

    django自带的wsgiref 在调试模式下使用的wsgi的文件,网关接口,协议
    
    uwsgi:协议
    
    uWSGI:具体实现方式

    安装

    ```
    pip3 install uwsgi -i https://pypi.douban.com/simple
    ```

    准备django程序

    启动

    ```
    cd django目录
    uwsgi --http :8080 --module mysite.wsgi
    ```

    配置文件格式

    ```
    conf
    py
    cnf
    xml
    json
    ini
    yaml
    ```

    配置文件启动#创建uwsgi配置文件

    Vim filepath/uwsgi.ini 


    ``` [uwsgi] http
    = :8080 #项目路径 chdir= /data/mysite # uwsgi的文件 wsgi-file= mysite/wsgi.py # 虚拟环境 # virtualenv = /root/env # 进程个数 processes = 2 # 线程个数 threads=2 # 后台启动,指定日志的输出 daemonize=/data/mysite/django.log # 清除临时文件 vacuum = true # python文件发生改变自动重启 py-autoreload=1 ```


    #通过配置文件启动uwsgi

    uwsgi --ini file
     

    nginx的配置文件

    ```
    server {
      listen 80;
      server_name crm.oldboy.com;
      location / {
        proxy_pass http://127.0.0.1:8080;
      }
      location /static {
        root /data/supercrm;
      }
    }
    ```

    在django的配置中要写入

    ```shell
    SATAIC_ROOT=os.path.join(BASE_DIR,'static/')
    ```

    执行命令

    ```SHELL
    python3 manager.py collectstatic #用来收集静态文件
    ```

    第二种配置方式

    ```shell
    uwsgi
    socket= :9090
    nginx的配置文件
    location / {
    include uwsgi_params;
    uwsgi_pass 127.0.0.1:8080;
    }
    ```

    第三种配置方式

    ```shell
    uwsgi
    socket = file.sock
    nginx的配置文件
    location /{
    include uwsgi_params;
    uwsgi_pass unix://file.sock
    }
    ```
  • 相关阅读:
    JavaScript概述
    JavaScript概述
    python语法基础
    python 网络编程
    python 日志模块
    python 异常处理
    python tricks
    记录_省赛(一)
    异或加密算法
    三目条件运算符
  • 原文地址:https://www.cnblogs.com/sun-10387834/p/12797321.html
Copyright © 2020-2023  润新知