zoukankan      html  css  js  c++  java
  • django部署(gunicorn版本)

    django部署

    采用 nginx + gunicorn + django部署,系统是centos7

    安装环境

    • nginx 安装

      1. 官网下载安装http://nginx.org/en/docs/

      2. 配置文件

        user  root;
        worker_processes  1;
        events {
            worker_connections  1024;
        }
        http {
            include       mime.types;
            default_type  application/octet-stream;
            sendfile        on;
            server {
                listen 80;
                server_name  youtubemp4.us;
                charset utf-8;
                client_max_body_size 10m;
                access_log  /var/log/nginx/build-access.log;
                error_log  /var/log/nginx/build-err.log;
                location /static/ {
                    #静态文件如js,css的存放目录
                    alias /root/en7/static/;
                }
                location / {
                    proxy_pass http://0.0.0.0:8000; # 这里要配合启动文件使用
                    proxy_set_header   Host                 $http_host;
                    proxy_set_header   X-Real-IP            $remote_addr;
                    proxy_set_header   X-Forwarded-For      $proxy_add_x_forwarded_for;
                    proxy_set_header   X-Forwarded-Proto    $scheme;
                }
            }
        }
        
      3. 软连接

        ln -s /usr/local/nginx/sbin/nginx /usr/bin/nginx

      4. 命令

        nginx -c xxx.conf
        nginx -s reload
        
    • gunicorn

      1. 安装

      pip install gunicorn

      1. 配置文件

        # /usr/bin/python3
        # encoding: utf-8
        import multiprocessing
        bind = '0.0.0.0:8000'      #绑定ip和端口号
        backlog = 512                #监听队列
        chdir = '/root/en7'  #gunicorn要切换到的目的工作目录
        timeout = 30      #超时
        
        workers = multiprocessing.cpu_count() * 2 + 1    #进程数
        threads = 2 #指定每个进程开启的线程数
        # 设置守护进程
        daemon = True
        
      2. 命令

        gunicorn 模块名.wsgi:application -c xxx.conf
        kill -9 pid
        
    • django

      1. 修改settings文件

        DEBUG = False
        ALLOWED_HOSTS = ["149.28.39.105","youtubemp4.us"]
        STATIC_ROOT = os.path.join(BASE_DIR, 'static')
        
        # STATICFILES_DIRS = [
        #     os.path.join(BASE_DIR,"static")
        # ]
        
      2. 执行收集静态文件

        python manager.py collectstatic
        

    部署步骤

    拉取django项目

    gunicorn启动django项目

    启动nginx服务器

  • 相关阅读:
    错误需要理由吗?(SQL Server 不存在或访问被拒绝)
    关于权限设计的轻量级实现
    ppc通过数据线与共享电脑上网
    解读.Net中的命名空间和程序集
    .Net XML 树
    软件开发教父与国内高手论道实录全文
    企业信息化, 该怎么规划?
    ASP.NET Portal Starter Kit中的角色验证
    用js实现类似分享到显示效果
    用js实现同一个页面多个渐变效果
  • 原文地址:https://www.cnblogs.com/huameixiao/p/13369186.html
Copyright © 2011-2022 走看看