• centos django nginx uwsgi


    django configuration

    settings.py

    DEBUG = False
    
    ALLOWED_HOSTS = ['*']
    
    TEMPLATES = [
        {
            ...
            'DIRS': [os.path.join(BASE_DIR, 'static')],
            ...
        }   
    ]
    
    STATIC_URL = '/static/'
    STATIC_ROOT = os.path.join(BASE_DIR, 'static')
    MEDIA_URL = '/media/'
    MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
    
    

    uwsgi configuration

    cd /usr/local/project/mysite
    touch uwsgi.log
    touch uwsgi.sock
    touch uwsgi.pid
    touch uwsgi.ini
    

    vim uwsgi.ini

    [uwsgi]
    chdir=/usr/local/project/mysite/
    module=mysite.wsgi:application
    workers=5
    pidfile=/usr/local/project/mysite/uwsgi.pid
    http=127.0.0.1:8001
    static-map=/static=/usr/local/project/mysite/static
    uid=root
    gid=root
    master=true
    vacuum=true
    thunder-lock=true
    enable-threads=true
    harakiri=30
    post-buffering=4096
    daemonize=/usr/local/project/mysite/uwsgi.log
    socket=/usr/local/project/mysite/uwsgi.sock
    

    nginx configuration

    vim /etc/nginx/nginx.conf

    events {
        worker_connections 1024;
    }
    
    http {
        include /etc/nginx/mime.types;
        default_type application/octet-stream;
    
        log_format main '$remote_addr - $remote_user [$time_local] "$request" '
                        '$status $body_bytes_sent "$http_referer" '
                        '"$http_user_agent" "$http_x_forwarded_for"';
        
        access_log /var/log/nginx/access.log main;
        
        sendfile on;
        #tcp_nopush on;
        
        keepalive_timeout 65;
    
        #gzip on;
        include /etc/nginx/conf.d/*.conf;
    }
    

    vim /etc/nginx/conf.d/mysite.conf ``` upstream django { server 127.0.0.1:8001; }

    server {
    listen 80;
    server_name server_name;
    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;
    charset utf-8;
    gzip on;
    gzip_types text/plain application/x-javascript text/css text/javascript application/x-httpd-php application/json text/json image/jpeg image/gif image/png application/octet-stream;

    error_page  404           /404.html; 
    error_page   500 502 503 504  /50x.html;
    
    client_max_body_size 75M;
    
    location /media/ {
        alias /ur/local/project/mysite/media/;
    }
    
    location /static/ {
        alias /usr/local/project/mysite/static/;
    }
    
    location / {
        include uwsgi_params;
        uwsgi_connect_timeout 30;
        uwsgi_pass unix:/usr/local/project/mysite/uwsgi.sock;
    }
    

    }

  • 相关阅读:
    git config 命令各参数有何区别
    Git 初始化
    Linux 安装 Git
    在Mac OS 上安装 Git
    maven 部署到远程仓库(私服)
    Git与SVN的区别
    windows挂载NFS文件系统无法访问/修改文件解决
    mysql5.7写入数据时间相差13/14小时解决
    mysql配置文件不生效解决
    springdata jpa mysql5.7写入中文乱码解决
  • 原文地址:https://www.cnblogs.com/otfsenter/p/8952504.html
Copyright © 2020-2023  润新知