• Python+django+uWSGI+Nginx


    Python3.5+Django+uWSGI

    安装Django

    pip3.5 install django

    安装 uWSGI

    pip install uwsgi

    新建 django_wsgi.py

     #!/usr/local/bin/python3.5
    import django
    import os
    
    import sys
    # 将系统的编码设置为UTF8
    #reload(sys)
    #sys.setdefaultencoding('utf8')
    
    sys.path.append("/root/cmdb_server-master")
    sys.path.append("/root/cmdb_server-master/cmdb")
    sys.path.append("/root/cmdb_server-master/cmdb_server")
    os.environ.setdefault("DJANGO_SETTINGS_MODULE","cmdb_server.settings")
    
    django.setup()
    from django.core.handlers.wsgi import WSGIHandler
    application = WSGIHandler()
    
    

    uwsgi启动方式

    直接命令行启动

    uwsgi --http :8000 --chdir /root/cmdb_server/cmdb_server/ --module django_wsgi

    利用配置文件启动(推荐)

    test110.ini

    [uwsgi]
    # http = 192.168.1.104:8000
    socket = 192.168.1.104:8000
    chdir = /root/cmdb_server
    module = wsgi
    processes = 4
    threads = 2
    enable-threads = True
    daemonize = /var/log/uwsgi.log
    buffer-size = 21573
    stats = 192.168.1.104:9000
    

    uwsgi --ini /root/cmdb_server/test110.ini

    安装Nginx

    wget http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm
    chmod +x nginx-release-centos-6-0.el6.ngx.noarch.rpm
    rpm -i nginx-release-centos-6-0.el6.ngx.noarch.rpm 
    yum install nginx -y
    

    /etc/nginx/conf.d/nginx.conf

    server{
            listen       80 ;    
            access_log /var/log/nginx/access.log;    
            error_log  /var/log/nginx/error.log;
            location / {
              # proxy_pass http://192.168.1.104:8000;  #跳转到 这个是HTTP协议
              include    /root/cmdb_server/uwsgi_params; 
              uwsgi_pass 192.168.1.104:8000; # uwsgi协议
            }
            error_page   500 502 503 504  /50x.html;
              location = /50x.html {
                  root   html;
            }
            location /static/ {
                alias  /root/cmdb_server/static/; 
            }
    }
    

    service nginx restart

    静态文件配置

    setting.py

    DEBUG = False
    STATIC_ROOT=os.path.join(BASE_DIR, "static/")

    python3.5 manage.py collectstatic

    先介绍下运行python manage.py collectstatic命令,配合STATIC_ROOT,会自动将各个app下的静态文件集中到STATIC_ROOT目录下

    如果以上安装出问题了

    yum install gcc
    yum install python-dev
    yum install python-dev*
    yum install python-setupto*
    
  • 相关阅读:
    JS解析JSON 注意事项总结
    Jquery 绑定标签事件
    System.Globalization.CultureInfo.InvariantCulture 解决不同地域字符串格式不同问题
    c# HttpWebRequest 模拟HTTP post 传递JSON参数
    Django REST framework (DRF) 不能用property或method排序
    django filters TypeError __init__() got an unexpected keyword argument 'lookup_type'
    DRF(Django Rest Framework)备忘
    测试服务器
    还款计算-复式记账
    Django 相关内容blog备忘
  • 原文地址:https://www.cnblogs.com/wspblog/p/7569394.html
Copyright © 2020-2023  润新知