環(huán)境:CentOS5.5+Nginx1.0+Python2.6.2+uwsgi0.9.7.7
1、升級Python 系統(tǒng)自帶的Python版本是2.4,我們需要升級到2.6.1,官網(wǎng)號稱是被屏蔽了,所以我們需要到網(wǎng)上搜索一個。
下載文件: http://download.huihoo.com/python/Python-2.6.1.tar.bz2 解壓: tar -jxvf Python-2.6.1.tar.bz2
編譯: cd cd Python-2.6.1 ./configure make make install
自此,python2.6安裝后路徑默認(rèn)是在/usr/local/lib/python2.6,查看Python版本:
/usr/local/bin/python2.6 -V
建立軟連接,使系統(tǒng)默認(rèn)的python指向python2.6 正常情況下即使python2.6安裝成功后,系統(tǒng)默認(rèn)指向的python仍然是2.4.3版本,所以我們需要做一個軟連接
mv /usr/bin/python /usr/bin/python.bak
ln -s /usr/local/bin/python2.6 /usr/bin/python
檢驗python指向是否成功 python -V
解決系統(tǒng)python軟鏈接指向python2.6版本后,yum不能正常工作 vi /usr/bin/yum 將文本編輯顯示的#/usr/bin/python修改為#/usr/bin/python2.4,保存修改即可
2、安裝uwsgi 目前最新的版本是0.9.7.2
下載文件: wget http://projects.unbit.it/downloads/uwsgi-0.9.7.2.tar.gz
uwsgi需要用到libxml2,系統(tǒng)自帶的版本無法使用,我們需要升級到libxml2-2.6.26 yum -y install libxml2*
編譯: tar -zxvf uwsgi-0.9.7.2.tar.gz cd uwsgi-0.9.7.2 make -f Makefile.Py26 #使用針對Python2.6的配置文件
編譯完成后,目錄下會生成可掃行文件 uwsgi,這樣編譯就算成功了。 我們可以將文件拷到/usr/bin目錄,方便使用 mv uwsgi /usr/bin
參考地址:http://projects.unbit.it/uwsgi/wiki/Install
3、安裝Nginx
下載文件: wget http://nginx.org/download/nginx-1.0.0.tar.gz
Nginx編譯需要pcre和openssl的支持,需要先安裝下: yum -y install pcre-devel openssl openssl-devel
編譯: ./configure --prefix=/usr/local/nginx make make instal
4、啟動uswgi服務(wù)
編寫一個簡單的wsgi程序,myapp.my def application(environ, start_response): start_response('200 OK', [('Content-Type', 'text/plain')]) yield 'Hello World\n'
運行uwsgi uwsgi -s 127.0.0.1:3031 -w myapp
正常情況下,會出現(xiàn)提示信息: *** Starting uWSGI 0.9.7.2 (32bit) on [Wed Apr 27 10:56:49 2011] *** compiled with version: 4.1.2 20080704 (Red Hat 4.1.2-50) on 27 April 2011 06:40:07 uWSGI running as root, you can use --uid/--gid/--chroot options *** WARNING: you are running uWSGI as root !!! (use the --uid flag) *** *** WARNING: you are running uWSGI without its master process manager *** your memory page size is 4096 bytes uwsgi socket 0 bound to TCP address 127.0.0.1:3031 fd 3 Python version: 2.6.1 (r261:67515, Apr 27 2011, 06:29:38) [GCC 4.1.2 20080704 (Red Hat 4.1.2-50)] Python main interpreter initialized at 0x883ed30 your server socket listen backlog is limited to 100 connections *** Operational MODE: single process *** WSGI application 0 (SCRIPT_NAME=) ready on interpreter 0x883ed30 (default app) *** uWSGI is running in multiple interpreter mode *** spawned uWSGI worker 1 (and the only) (pid: 1208, cores: 1)
參考地址:http://projects.unbit.it/uwsgi/wiki/Doc095
5、配置并啟動Nginx 編輯Nginx配置文件 vim /usr/local/nginx/conf/nginx.conf
加入: location / {
uwsgi_pass 127.0.0.1:3031; include uwsgi_params; 在本機3031端口監(jiān)聽。
在瀏覽器里輸入http://localhost 將提示如下信息: Hello World 說明平臺已經(jīng)OK了
|