运行django的有fast_cgi、uwsgi和gunicorn等 其中uwsgi效能最好 但配置稍复杂 而gunicorn配置简单
在windows下通过源码安装gunicorn报错 缺少fcntl模块 最好在linux环境下使用
首先安装gunicorn 和django
gunicorn_django -D -b 127.0.0.1:8000
然后配下nginx
server {
listen 80;
server_name 域名;
root django项目目录 ;
location /static/ {
if ($query_string) {
expires max;
# log_not_found off;
}
}
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
if (!-f $request_filename) {
proxy_pass http://127.0.0.1:8000;
break;
}
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /media/50x.html;
}
参考网站(http://gunicorn.org/, )