Python Linux uswgi 的环境配置简单记录


在配置之前要安装好对应的nginx和python和django
1:下载uwsgi-1.4.4.tar.gz
#tar -zxvf uwsgi-1.4.4.tar.gz
#cd uwsgi-1.4.4
#python setup.py install
#cp uwsgi /usr/bin/
# cd nginx/
#cp uwsgi_param /usr/local/nginx/conf
2:配置nginx 如下:
  server{
        listen 80;
        server_name python.ch.gongchang.cn;
        access_log /var/log/python/access.log;
        error_log /var/log/python/error.log;
        location /{
            root /root/workspace/mysite/;#项目的路径
            uwsgi_pass 127.0.0.1:8000;
            include uwsgi_params;
        }

    }

3:配置pythonDjango:
在 /root/workspace/mysite/mysite 目录下建立wsgi.xml(文件名称可以是任意的)内容如下:
<uwsgi>
    <socket>127.0.0.1:8000</socket>
    <master>true</master>
    <pythonpath>/root/workspace/mysite/</pythonpath> <!-- the path is manage.py's path-->
    <module>wsgi</module> <!-- This is wsgi.ph file path-->
</uwsgi>

4:陪在wsgi.py文件:
import os,sys
if not os.path.dirname(__file__) in sys.path[:1]:
    sys.path.insert(0,os.path.dirname(__file__))
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings")
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()#如果这个地方错误的话会提示:

uWSGI Error

Python application not found
这个配置是错误是不正确的在django.1.4 也会报上面的错误的。
from django.core.handlers.wsgi import WSGIHandler
application = WSGIHandler()

 

 

 


   

 

 

posted @ 2013-01-13 18:14 Linux、Mongo、Php、Shell、Python、C 阅读(...) 评论(...) 编辑 收藏