安裝uwsgi
pip install uwsgi
安裝nginx
apt-get install nginx
在項(xiàng)目目錄下創(chuàng)建 app_uwsgi.ini
[uwsgi]
# Django-related settings
# the base directory (full path)
chdir = /data/www/vhosts/pro/ #項(xiàng)目地址
# Django's wsgi file
module = apps.wsgi #項(xiàng)目wsgi 地址
# the virtualenv (full path)
# home = / #virtualenv 項(xiàng)目目錄
# process-related settings
# master
master = true
# maximum number of worker processes
processes = 10
# the socket (use the full path to be safe
socket = /data/www/vhosts/pro/uwsgi.sock #項(xiàng)目sock文件
# ... with appropriate permissions - may be needed
chmod-socket = 664
# clear environment on exit
vacuum = true
pidfile = /data/www/vhosts/pro/uwsgi.pid #pid文件地址
plugins = python #不加會出現(xiàn)502
buffer-size=32768 # 解決 invalid request block size: 21573 (max 4096)...skip錯誤
創(chuàng)建 uwsgi_params 文件
uwsgi_param QUERY_STRING $query_string;
uwsgi_param REQUEST_METHOD $request_method;
uwsgi_param CONTENT_TYPE $content_type;
uwsgi_param CONTENT_LENGTH $content_length;
uwsgi_param REQUEST_URI $request_uri;
uwsgi_param PATH_INFO $document_uri;
uwsgi_param DOCUMENT_ROOT $document_root;
uwsgi_param SERVER_PROTOCOL $server_protocol;
uwsgi_param UWSGI_SCHEME $scheme;
uwsgi_param REMOTE_ADDR $remote_addr;
uwsgi_param REMOTE_PORT $remote_port;
uwsgi_param SERVER_PORT $server_port;
uwsgi_param SERVER_NAME $server_name;
nginx 配置
upstream django {
server unix:///data/www/vhosts/pro/uwsgi.sock;
}
server {
listen 80;
listen 443;
server_name www.xx.com xx.com;
access_log /var/log/nginx/website.net.access_log;
error_log /var/log/nginx/website.net.error_log;
location /static/ { # MEDIA_URL
alias /data/www/vhosts/pro/static/; # MEDIA_ROOT
expires 5d;
client_max_body_size 1000m;
}
location /media/ { # MEDIA_URL
alias /data/www/vhosts/pro/media/; # MEDIA_ROOT
expires 5d;
}
location /static/admin/ { # MEDIA_URL
alias /usr/local/lib/python2.7/dist-packages/django/contrib/admin/static/admin/; # MEDIA_ROOT
expires 90d;
}
location / {
#proxy_pass http://website/;
uwsgi_pass django;
include /data/www/vhosts/pro/uwsgi_params;
}
}
注意: /data/www/vhosts/pro/ 目錄為你的項(xiàng)目路徑
啟動命令
uwsgi --ini apps_uwsgi.ini
重啟服務(wù)
uwsgi --reload uwsgi.pid
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者