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;
}

}

posted @ 2018-04-26 15:05  idlewith  阅读(125)  评论(0编辑  收藏  举报