Ubuntu 14.04+Django 1.7.1+Nginx+uwsgi部署教程
具体环境:
Ubuntu14.04Python2.7.6Django1.7.1Virtualenvname:testNginxuwsgi
假设项目文件夹位于/data/www/ts设置保存在./conf
virtualenvname=test domainname=example.com
django+uwsgi的部署实在是太蛋疼了..网上已有的教程似乎有新版本的兼容问题。最后跑到uwsgi官网上找的教程终于跑通了..
不过官网的教程似乎有引导教学性质,部署的时候就显得很绕弯路,在这里记录下来精简内容
http://uwsgi-docs.readthedocs.org/en/latest/tutorials/Django_and_nginx.html
首先,需要一个uwsgi_params文件,放在项目的conf文件夹里面。之后需要指向它。文件内容如下:
uwsgi_paramQUERY_STRING$query_string; uwsgi_paramREQUEST_METHOD$request_method; uwsgi_paramCONTENT_TYPE$content_type; uwsgi_paramCONTENT_LENGTH$content_length; uwsgi_paramREQUEST_URI$request_uri; uwsgi_paramPATH_INFO$document_uri; uwsgi_paramDOCUMENT_ROOT$document_root; uwsgi_paramSERVER_PROTOCOL$server_protocol; uwsgi_paramHTTPS$httpsif_not_empty; uwsgi_paramREMOTE_ADDR$remote_addr; uwsgi_paramREMOTE_PORT$remote_port; uwsgi_paramSERVER_PORT$server_port; uwsgi_paramSERVER_NAME$server_name;
创建一个叫做ts_nginx.conf的文件,内容如下
#ts_nginx.conf
#theupstreamcomponentnginxneedstoconnectto upstreamdjango{ #serverunix:///path/to/your/mysite/mysite.sock;#forafilesocket server127.0.0.1:8001;#forawebportsocket(we'llusethisfirst) }
#configurationoftheserver server{ #theportyoursitewillbeservedon listen80; #thedomainnameitwillservefor server_name.example.com;#substituteyourmachine'sIPaddressorFQDN charsetutf-8;
#maxuploadsize client_max_body_size75M;#adjusttotaste
#Djangomedia location/media{ alias/data/www/ts/media;#yourDjangoproject'smediafiles-amendasrequired }
location/static{ alias/data/www/ts/static;#yourDjangoproject'sstaticfiles-amendasrequired }
#Finally,sendallnon-mediarequeststotheDjangoserver. location/{ uwsgi_passdjango; include/data/www/ts/conf/uwsgi_params;#theuwsgi_paramsfileyouinstalled } }