Tags : Ajax  apache  awk  besttrace  bootstrap  CDN  Django  git 

常见问题

实践:配置Nginx+UWSGI

stevezhou      2014.08.22   


配置 uwsgi :
在django项目目录添加文件 django_wsgi.py、uwsgi.xml;

----django_wsgi.py----

#!/usr/local/bin/python
import os,sys
if not os.path.dirname(__file__) in sys.path[:1]:
   sys.path.insert(0, os.path.dirname(__file__))
os.environ['DJANGO_SETTINGS_MODULE'] = 'myblog.settings'
#django1.6.5
from django.core.handlers.wsgi import WSGIHandler
application = WSGIHandler()
#djang1.7+
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

----uwsgi.xml----    #要用xml进行配置,最好在安装uwsgi前安装好libxml2库,以支持对xml的解析

<uwsgi>
 <socket>127.0.0.1:9001</socket>
 <chdir>/var/www/myblog</chdir>
 <pathonpath>..</pathonpath>
 <module>django_wsgi</module>
</uwsgi>

启动该xml配置:uwsgi -x /var/www/myblog/uwsgi.xml

 

配置Nginx:

发现在nginx.conf 中有如下语句: 

include /alidata/server/nginx/conf/vhosts/*.conf;

表示可以在/vhosts/ 配置多个.conf文件(适用于多个网站,一个网站对应一个.conf配置文件):

----stevezhou.conf ----

server {
        listen       80;
        server_name  localhost;
	index index.html index.htm index.php;
	root /var/www/myblog;
	location /
	{
		uwsgi_pass	127.0.0.1:9001;
		include	/alidata/server/nginx/conf/uwsgi_params;
	}
	
	location ~ ^/static/
	{
		root	/var/www/myblog;
		expires	24h;
		access_log	off;
	}

	location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
	{
		expires 30d;
	}
	location ~ .*\.(js|css)?$
	{
		expires 1h;
	}
	#伪静态规则
	include /alidata/server/nginx/conf/rewrite/default.conf;
	access_log  /alidata/log/nginx/access/default.log.stevezhou;
}
----phpwind.conf----
server {
        listen       8001;
        server_name  localhost;
        index index.html index.htm index.php;
        root /alidata/www/phpwind;
        location ~ .*\.(php|php5)?$
        {
                #fastcgi_pass  unix:/tmp/php-cgi.sock;
                fastcgi_pass  127.0.0.1:9000;
                fastcgi_index index.php;
                include fastcgi.conf;
        }
        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
        {
                expires 30d;
        }
        location ~ .*\.(js|css)?$
        {
                expires 1h;
        }
        #伪静态规则
        include /alidata/server/nginx/conf/rewrite/phpwind.conf;
        access_log  /alidata/log/nginx/access/phpwind.log;
}

参考:

http://www.nowamagic.net/academy/part/13/302/

http://help.aliyun.com/view/11108189_13495139.html?spm=5176.7224445.1997283057.8.Wedesy



标签 :  配置 上一篇     下一篇