初试nginx+uwsgi+django[1]
环境操作系统 centos 6.2 x64
—————————————
1.安装:
省略,只记录一下nginx版本和编译参数
nginx1.11
prefix=/usr/local/nginx –with-pcre=/usr/local/src/pcre-8.21 –with-http_stub_status_module –user=gameserver –group=gameserver –with-http_ssl_module
centos 6.2 已经自带 python2.6 了,其他版本的话自己yum -y install python
wget http://www.djangoproject.com/download/1.2.3/tarball/
cd Django-1.2.3
python setup.pyinstall
安装成功会出现这个字样
running install_egg_info
Writing /usr/lib/python2.6/site-packages/Django-1.2.3-py2.6.egg-info
wgethttp://projects.unbit.it/downloads/uwsgi-0.9.6.8.tar.gz
tar -zxvfuwsgi-0.9.6.8.tar.gz
cd uwsgi-0.9.6.8
make
出现报错 ******* libxml2 headers unavailable
解决办法: yum -y install libxml2-devel
继续make
出现报错
wsgi.h:125:20: error: Python.h: No such file or directory
In file included from utils.c:1:
uwsgi.h:149: error: expected ‘)’ before ‘*’ token
uwsgi.h:150: error: expected ‘)’ before ‘*’ token
uwsgi.h:310: error: expected specifier-qualifier-list before ‘PyThreadState’
uwsgi.h:492: error: expected specifier-qualifier-list before ‘PyThreadState’
分析:
查看/usr/include/python2.6目录,的确没有python.h
解决办法:
yum -y install python-devel
继续make
成功了,编译成功后出现以下字样
*** uWSGI is ready, launch it with ./uwsgi ***
cpuwsgi /usr/local/uwsgi/bin/
2.配置:
mkdir-p/usr/local/uwsgi/bin/
mkdir-p /usr/local/uwsgi/conf
mkdir -p /usr/local/uwsgi/logs
cd/usr/local/uwsgi/conf
viuwsgi.xml
—
127.0.0.1:9001
200
true
/usr/local/uwsgi/logs/uwsgi.pid
8
/usr/local/python_web/www
/usr/local/python_web
django_wsgi
true
true
true
true
6048
/usr/local/uwsgi/logs/django.log
—
创建应用模块
mkdir -p /usr/local/python_web/
cd/usr/local/python_web/
django-admin.py startprojectwww
( 注:要看到www目录下的这几个文件才算成功 __init__.pymanage.pysettings.pyurls.py)
cd /usr/local/python_web/www/
vi django_wsgi.py
—
import os
os.environ['DJANGO_SETTINGS_MODULE'] = ‘www.settings’
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
–
server {
listen80;
server_name xx.com;
location / {
uwsgi_pass 127.0.0.1:9001;
include uwsgi_params;
}
}
3.启动服务
/usr/local/uwsgi/bin/uwsgi -x /usr/local/uwsgi/conf/uwsgi.xml
检查启动状态
netstat -tunlp |grep 9001
tcp 0 0 127.0.0.1:9001 0.0.0.0:* LISTEN 8830/uwsgi
测试访问
配置 xx.com的host之后,访问 http://xx.com
就可以看到页面
————————-
It worked!
Congratulations on your first Django-powered page.
Of course, you haven’t actually done any work yet. Here’s what to do next:
If you plan to use a database, edit the DATABASES setting in www/settings.py.
Start your first app by running python www/manage.py startapp .
————————————————————————————–
这样就算成功了
但是到了这里,我其实还不是很懂 uwsgi ,django,nginx 之间的关系
我暂时理解为 nginx 和 uwsgi 的关系,就好像 nginx 和 fastcgi 一样, uwsgi 为nginx解析python程序
页:
[1]