热搜:

CentOS+nginx+uwsgi+Python 多站点环境搭建

2013-10-21 20:08:02文章来源:点点软件园热度:0

更多

环境:更多最新IT资讯尽在金顺软件园http://www.jinshun168.com/

CentOS X64 6.4

nginx 1.5.6

Python 2.7.5

一:安装需要的类库及Python2.7.5

安装必要的开发包

yum groupinstall "Development tools"

yum install zlib-devel bzip2-devel pcre-devel openssl-devel ncurses-devel sqlite-devel readLINE-devel tk-devel

CentOS 自带Python2.6.6,但我们可以再安装Python2.7.5:

cd ~
wget http://python.org/ftp/python/2.7.5/Python-2.7.5.tar.bz2
tar xvf Python-2.7.5.tar.bz2
cd Python-2.7.5
./configure --prefix=/usr/local
make && make altinstall

安装完毕后,可是使用”python2.7”命令进入python2.7的环境。

二:安装Python包管理

easy_install包 https://pypi.python.org/pypi/distribute

方便安装Python的开发包

cd ~
wget https://pypi.python.org/packages/source/d/distribute/distribute-0.6.49.tar.gz
tar xf distribute-0.6.49.tar.gz
cd distribute-0.6.49
python2.7 setup.py install
easy_install --version

红色部分必须是“python2.7”,否则将安装到默认的2.6环境内。

pip包 https://pypi.python.org/pypi/pip

安装pip的好处是可以pip list、pip uninstall 管理Python包, easy_install没有这个功能,只有uninstall

easy_install pip
pip --version

三:安装uwsgi

uwsgi:https://pypi.python.org/pypi/uWSGI

uwsgi参数详解:http://uwsgi-docs.readthedocs.org/en/latest/Options.html

pip install uwsgi
uwsgi --version

测试uwsgi是否正常:

新建test.py文件,内容如下:

def application(env, start_response):
        start_response('200 OK', [('Content-Type','text/html')])
        return "Hello World"

然后在终端运行:

uwsgi --http :8001 --wsgi-file test.py

在浏览器内输入:http://127.0.0.1:8001,看是否有“Hello World”输出,若没有输出,请检查你的安装过程。

四:安装django

pip install django

测试django是否正常,运行:

django-admin.py startproject demosite
cd demosite
python2.7 manage.py runserver 0.0.0.0:8002

在浏览器内输入:http://127.0.0.1:8002,检查django是否运行正常。

五:安装nginx

以上,就是金顺软件园小编给大家带来的CentOS+nginx+uwsgi+Python 多站点环境搭建全部内容,希望对大家有所帮助!

上一篇梦三国 夏侯渊玩法攻略下一篇万万没想到,王大锤传奇-优酷自制翻身之作如何应对大成本生产模
编辑:点点小编