Nginx+uwsgi+Django (Python web环境)

nginx配置文件

[root@DB02 rc3.d]# vi /application/nginx/conf/nginx.confuser  root;worker_processes  1;events {    worker_connections  1024;}#}http {    include       mime.types;    default_type  application/octet-stream;    sendfile        on;    keepalive_timeout  65;    upstream django {        server unix:///tmp/project.sock; # for a file socket    }     server {        listen       80;        server_name  da.yilongzc.com;        location  /static {       alias /root/shell/DataShow/static; # your Django project's static files - amend as required        send_timeout 500;        proxy_read_timeout 500;        proxy_connect_timeout 500;        }        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$        {                root /root/shell/DataShow/;                if (-f $request_filename) {                expires 1d;                break;                }        }        location ~ .*\.(js|css)$                {                root /root/shell/DataShow/;                if (-f $request_filename) {                expires 1d;                break;        }        }        location / {           uwsgi_send_timeout 500;           uwsgi_connect_timeout 500;           proxy_read_timeout 500;           uwsgi_read_timeout 500;           uwsgi_ignore_client_abort on;           uwsgi_pass  django;           include     uwsgi_params;        }    }}

通过/tmp/project.sock 文件,将nginx与uwsgi关联,进行通信

注意:要放到/tmp 下,否则会报403 没有权限

nginx配置文件中的超时时间,是为了解决504 time-out文件,主要是因为后端python环境,请求数据时,没有在指定时间内返回数据,所以出现这个问题,运维这边只能调整超时参数,或者找开发去优化SQL语句,在或者拆分他们的业务,将1个页面,分成多个小页面去请求