• nginx基于uwsgi部署Django


    1.安装nginx

    yum install -y nginx(需要epel源)

    2.安装uwsgi

    yum groupinstall "Development tools"
    yum install zlib-devel bzip2-devel pcre-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel
    pip install -y uwsgi

    3.安装django

    pip install django

    4.创建django项目

    django-admin startproject mysite

    5.创建app

    python manage.py startapp  web

    6.修改mysite/settings.py

    ALLOWED_HOSTS = ['*']

    7.修改mysite/urls.py

    from app01 import views
    urlpatterns = [
        url(r'^admin/', admin.site.urls),
        url(r'^hello_django/', views.hello),
    ]

    8.修改web/view.py

    from django.shortcuts import render,HttpResponse
    
    # Create your views here.
    def hello(request):
        print('request is :',request)
        return HttpResponse('django is ok ')

    9.启动程序

    uwsgi --http :8000 --module mysite.wsgi

    10uwsgi配置文件

    uwsgi支持ini、xml等多种配置方式,本文以 ini 为例, 在/etc/目录下新建uwsgi_nginx.ini,添加如下配置:
    
    [uwsgi]
    http = 0.0.0.0:8000
    #the local unix socket file than commnuincate to Nginx
    socket = /data/mysite/mysit.socket
    # the base directory (full path)
    chdir = /data/mysite
    # Django's wsgi file
    wsgi-file = mysite/wsgi.py
    # maximum number of worker processes
    processes = 4
    #thread numbers startched in each worker process
    threads = 2
    # clear environment on exit
    vacuum          = true
    daemonize = /data/mysite/uwsgi.log
    py-autoreload=1

    11.修改配置文件权限

    chown nginx.root uwsgi_params

    12.修改nginx配置文件

    location / {
            include  /data/mysite/conf/uwsgi_params;
            proxy_pass http://127.0.0.1:8000;
                root   html;
                index  index.html index.htm;
            }
            }
    location /static{
         alias /data/mysite/static;   
     }
         #nginx处理媒体资源
    location /media{
         alias /data/mysite/media;  
     }

    13.执行命令 迁移nginx静态文件

    STATIC_ROOT = os.path.join(BASE_DIR, "static/")
    python manage.py collectstatic
  • 相关阅读:
    GOOGLE's Olympics Symbols
    写在九月的第一篇
    有点沉重的topic:出国,考研,工作?
    放弃的选择
    面临选择
    中秋节快乐!
    我该做一些改变
    使用Docker搭建一个WordPress博客
    三层架构小示例
    SQL联合查询
  • 原文地址:https://www.cnblogs.com/chenxi67/p/10414020.html
Copyright © 2020-2023  润新知