手机版
你好,游客 登录 注册
背景:
阅读新闻

CentOS+Nginx+uWSGI+Python 多站点环境搭建

[日期:2013-12-20] 来源:Linux社区  作者:xiongpq [字体:大 中 小]

环境:

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

cd ~
wget http://nginx.org/download/nginx-1.5.6.tar.gz
tar xf nginx-1.5.6.tar.gz
cd nginx-1.5.6
./configure --prefix=/usr/local/nginx-1.5.6 \
--with-http_stub_status_module \
--with-http_gzip_static_module
make && make install

推荐阅读:

你应该使用 Nginx + uWSGI http://www.linuxidc.com/Linux/2013-07/87286.htm

uWSGI + Nginx 部署 Flask Web 应用 http://www.linuxidc.com/Linux/2013-06/85828.htm

Django+Nginx+uWSGI 部署 http://www.linuxidc.com/Linux/2013-02/79862.htm

Linux下Nginx+uWSGI部署Python应用 http://www.linuxidc.com/Linux/2012-10/72443.htm

Ubuntu Server 12.04 安装Nginx+uWSGI+Django环境 http://www.linuxidc.com/Linux/2012-05/60639.htm

CentOS 5.5 + Nginx 0.8.50 + uWSGI + Django 1.2.3 部署Django项目 http://www.linuxidc.com/Linux/2011-05/36399.htm

Nginx 的详细介绍:请点这里
Nginx 的下载地址:请点这里

linux
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款