• python django 的环境搭建(centos)


    一、安装好nginx

    二、安装uwsgi

    yum install python-devel -y
    pip3 install uwsgi
    
    #测试启动django
    /usr/local/python3/bin/uwsgi  --http  :9000 --chdir /data/www/untitled2/  --wsgi-file  /data/www/untitled2/untitled2/wsgi.py  --master --processes 4 --threads 2 --stats 0.0.0.0:9002
    
    #常用参数
    http : 协议类型和端口号
    processes : 开启的进程数量
    workers : 开启的进程数量,等同于processes(官网的说法是spawn the specified number ofworkers / processes)
    chdir : 指定运行目录(chdir to specified directory before apps loading)
    wsgi-file : 载入wsgi-file(load .wsgi file)
    stats : 在指定的地址上,开启状态服务(enable the stats server on the specified 
    address)
    threads : 运行线程。由于GIL的存在,我觉得这个真心没啥用。(run each worker in prethreaded
    master : 允许主进程存在(enable master process)
    daemonize : 使进程在后台运行,并将日志打到指定的日志文件或者udp服务器(daemonize uWSGI)。实际上最常用的,还是把运行记录输出到一个本地文件上。
    pidfile : 指定pid文件的位置,记录主进程的pid号。
    vacuum : 当服务器退出的时候自动清理环境,删除unix socket文件和pid文件(try to remove all of the generated file/sockets)
    
    注意:–wsgi-file后面跟的是相对目录
    
    #测试 浏览器访问ip:9000端口
    

      

    三、写入文件中

    [root@iZ2819itt6xZ ~]# cat /data/www/untitled2/untitled2/uwsgi.ini 
    [uwsgi]
    http = :9000
    chdir  = /data/www/untitled2
    module = untitled2.wsgi
    master = true
    processes = 2
    vacuum = true
    daemonize = /data/logs/uwsgi.log
    
    ##启动
    /usr/local/python3/bin/uwsgi  --ini  /data/www/untitled2/untitled2/uwsgi.ini  
    

      

    四、nginx使用

    upstream django_ops {
        server 127.0.0.1:9000;
    }
    server {
        listen      888;
        server_name 10.0.0.141;
        charset     utf-8;
         
        location /  {
            charset  utf-8; 
                include uwsgi_params;
                proxy_pass http://127.0.0.01:9000;
                uwsgi_read_timeout 1800;
    
        }
        rewrite ^/$ http://10.0.0.141:888/index/  ;  #访问/跳转到index页面
        location /static/ {
            alias /data/www/untitled2/te1_django/static/;
    
        }
    
    
    }
    

      

  • 相关阅读:
    python的gui库tkinter
    python图像处理库Pillow基本使用方法
    github配置SSH proxy
    python的pandas库读取csv
    学习app开发思路
    shell脚本中四则运算
    shell脚本实例三
    shell脚本实例二
    shell脚本实例一
    LINUX系统下的shell命令---grep、sed、awk
  • 原文地址:https://www.cnblogs.com/zhangb8042/p/9994631.html
Copyright © 2020-2023  润新知