Centos5.4+Nginx-0.8.50+UWSGI-0.9.6.2+Django-1.2.3搭建高性能WEB服务器[原创] 不指定

刘天斯 , 2010/10/13 20:42 , Linux , 评论(10) , 阅读(37787) , Via 本站原创 | |
     之前一直使用Nginx+Fastcgi来搭建python web服务器,本文介绍Nginx+UWSGI组合来实现。uWSGI 是一个快速的、纯C语言开发的、自维护的、对开发者友好的WSGI服务器,旨在提供专业的 Python web应用发布和开发。它更符合python web的标准协议,速度要比Fastcgi要快、性能更加稳定。
一、安装平台
1、安装pcre
引用

cd /home
mkdir -p /home/install/nginx && cd /home/install/nginx
wget http://ftp.exim.llorien.org/pcre/pcre-8.00.tar.gz
tar -zxvf pcre-8.00.tar.gz
cd pcre-8.00
./configure
make && make install
cd ..

2、安装Nginx
引用

wget http://nginx.org/download/nginx-0.8.50.tar.gz
tar -zxvf nginx-0.8.50.tar.gz
cd nginx-0.8.50/
./configure --user=nobody --group=nobody --prefix=/usr/local/nginx --with-http_stub_status_module --with-cc-opt='-O3' --with-cpu-opt=opteron
make && make install
cd ..

3、安装python&Mysql-python
引用

wget http://www.python.org/ftp/python/2.5.1/Python-2.5.1.tgz
tar -zxvf Python-2.5.1.tgz
cd Python-2.5.1
./configure && make && make install
echo "export PATH=\$PATH:/usr/local/bin" >> /etc/profile
source /etc/profile

4、安装MySql-python
引用

cd ../
wget http://downloads.sourceforge.net/project/mysql-python/mysql-python/1.2.2/MySQL-python-1.2.2.tar.gz?r=&ts=1285248455&use_mirror=nchc
cd MySQL-python-1.2.2
python setup.py install

5、安装Django
引用

wget http://www.djangoproject.com/download/1.2.3/tarball/
tar -zxvf Django-1.2.3.tar.gz
cd Django-1.2.3
python setup.py install
cd ..

6、安装uWSGI
引用

wget http://projects.unbit.it/downloads/uwsgi-0.9.6.2.tar.gz
tar -zxvf uwsgi-0.9.6.2.tar.gz
cd uwsgi-0.9.6.2
make
cp uwsgi /usr/bin

二、平台配置
1、平台环境说明
  1.1、项目位置:/opt/www/Purgesys
   创建项目方法:
引用

cd /opt/www
django-admin.py startproject Purgesys

  1.2、查看项目(出现以下文件结构说明项目已创建成功)
  #tree Purgesys
引用

Purgesys
|-- __init__.py
|-- manage.py
|-- settings.py
`-- urls.py

2、Nginx相关配置
#cd /usr/local/nginx/conf
#vi django_uwsgi.conf

*Nginx-0.8.50默认已添加uwsgi输出头支持
include uwsgi_params;

#vi nginx.conf
追加子配置文件django_uwsgi.conf

3、UWSGI配置
#mkdir -p /home/uwsgi;cd /home/uwsgi
#mkdir -p /opt/www/logs
#echo "" > /opt/www/logs/django.log
#vi uwsgi.xml

4、创建应用模块
cd /opt/www/Purgesys
vi django_wsgi.py

5、启动服务
#/usr/bin/uwsgi -x /home/uwsgi/uwsgi.xml
#/usr/local/nginx/sbin/nginx

6、查看进程
#[liuts@webserver nginx]# ps -ef|grep uwsgi|grep -v grep
引用

root     21652     1  0 17:12 ?        00:00:00 /usr/bin/uwsgi -x /home/uwsgi/uwsgi.xml
root     21653 21652  0 17:12 ?        00:00:00 /usr/bin/uwsgi -x /home/uwsgi/uwsgi.xml
root     21654 21652  0 17:12 ?        00:00:00 /usr/bin/uwsgi -x /home/uwsgi/uwsgi.xml
root     21655 21652  0 17:12 ?        00:00:00 /usr/bin/uwsgi -x /home/uwsgi/uwsgi.xml
root     21656 21652  0 17:12 ?        00:00:00 /usr/bin/uwsgi -x /home/uwsgi/uwsgi.xml
root     21657 21652  0 17:12 ?        00:00:00 /usr/bin/uwsgi -x /home/uwsgi/uwsgi.xml
root     21658 21652  0 17:12 ?        00:00:00 /usr/bin/uwsgi -x /home/uwsgi/uwsgi.xml
root     21659 21652  0 17:12 ?        00:00:00 /usr/bin/uwsgi -x /home/uwsgi/uwsgi.xml
root     21660 21652  0 17:12 ?        00:00:00 /usr/bin/uwsgi -x /home/uwsgi/uwsgi.xml

7、监听端口
#[liuts@webserver nginx]# netstat -an|grep 9000
引用

tcp        0      127.0.0.1:9000                0.0.0.0:*                   LISTEN

8、访问测试
输入http://serverip/
点击在新窗口中浏览此图片
大功告成!

*附uwsgi启动脚本
#cd /home/uwsgi
#vi uwsgiserver.sh

#sh uwsgiserver.sh start
[uWSGI] parsing config file /home/uwsgi/uwsgi.xml
Start uwsgi service [OK]

如大家有什么疑问或感兴趣的话题可以通过weibo与我交流:http://t.qq.com/yorkoliu
Tags: , , ,
balabalaaaa Email Homepage
2015/10/21 10:37
细节没讲清楚.菜鸟按这流程,配置不出来好吧!
fcds Homepage
2014/10/30 18:32
failed to open python file Purgesys/django_wsgi我看LOG出现这个问题。。。使用的是官网推荐的 .ini配置文件
Selboo Homepage
2012/02/06 12:02
MySQL-python 安装错误如下
from setuptools import setup ImportError:

先安装
python ez_setup.py

在安装
python setup.py install

贴一下,方便其他兄弟了
刘天斯 回复于 2012/02/06 21:26
好同学。
junior sa Email
2011/11/15 23:55
我的nginx+uwsgi+django遇到大header的request,经常出现502,uwsgi报的是 invalid request header size,何解我的uwsgi配置为[uwsgi]socket = :8010master = truemodule = django_wsgiprocesses = 8home = /path/to/virtualenvharakiri = 20daemonize = /path/to/uwsgi.logpidfile = /path/to/uwsgi.pidpythonpath = /path/to/projectpythonpath = /path/to/uwsgibuffer-size = 32768reload-mercy = 8max-requests = 5000socket-timeout = 4
刘天斯 回复于 2011/11/16 09:18
大header可以修改nginx http head部分参数。
python初学
2011/09/14 21:15
补充一点:Nginx报502,但是uwsgi正常启动端口9000也正常监听。有可能是应用程序有错误导致。
刘天斯 回复于 2011/09/14 23:00
对头
33333333333
2011/09/01 15:20
invalid request block size:  报这个错误是什么原因 呀
scoke
2011/05/19 16:21
问题已经解决了,是启动的配置文件uwsgi.xml
不正常内存限制导致的
刘天斯 回复于 2011/05/19 18:01
Good
scoke
2011/05/17 17:25
不好意思,现在错误变成了
{address space usage: 120582144 bytes/114MB} {rss usage: 3883008 bytes/3MB} [pid: 18721|app: -1|req: -1/1] 192.168.216.1 () {42 vars in 677 bytes} [Tue May 17 17:14:03 2011] GET / => generated 46 bytes in 0 msecs (HTTP/1.1 500) 2 headers in 63 bytes (0 switches on core 0)
发现修改了vi django_wsgi.py这个文件,之前写错
scoke
2011/05/17 16:33
你好,安装你的教程配置了2遍,还有也参考了其他的教程,始终不能访问,访问的时候是502 Bad Gateway
错误日志是
ue May 17 16:29:43 2011 - Respawned uWSGI worker (new pid: 18487)
Tue May 17 16:29:43 2011 - DAMN ! process 18477 died :( trying respawn ...
Tue May 17 16:29:43 2011 - worker respawning too fast !!! i have to sleep a bit...
Tue May 17 16:29:45 2011 - Respawned uWSGI worker (new pid: 18488)
Tue May 17 16:29:45 2011 - DAMN ! process 18478 died :( trying respawn ...
Tue May 17 16:29:45 2011 - worker respawning too fast !!! i have to sleep a bit...
Tue May 17 16:29:47 2011 - Respawned uWSGI worker (new pid: 18489)
Tue May 17 16:29:47 2011 - DAMN ! process 18484 died :( trying respawn ...
Tue May 17 16:29:47 2011 - worker respawning too fast !!! i have to sleep a bit...
Tue May 17 16:29:49 2011 - Respawned uWSGI worker (new pid: 18490)
帮忙看一下,谢谢
fh.cn Email Homepage
2010/10/14 13:48
来拜访天师的新文章,很不错,不过我们没用python
分页: 1/1 第一页 1 最后页
发表评论

昵称

网址

电邮

打开HTML 打开UBB 打开表情 隐藏 记住我 [登入] [注册]