2019独角兽企业重金招聘Python工程师标准>>>
相关页面:
http://webpy.org/install
http://uwsgi-docs.readthedocs.org/en/latest/WSGIquickstart.html
http://projects.unbit.it/uwsgi/wiki/Example
uwsgi的安装需要python-devel,可以使用yum search python-devel进行查找
没有的话可以到
http://www.rpmfind.net/进行相关rpm包进行查找
uwsgi安装:
wget http://projects.unbit.it/downloads/uwsgi-latest.tar.gz
tar zxvf uwsgi-latest.tar.gz
cd <dir>
make
生成可执行的二进制文件uwsgi
文件位置:
mkdir /home/uwsgi
mv uwsgi /home/uwsgi/
web.py安装:
http://webpy.org/install
python setup.py install 在解压的tar包中进行安装
简单运行文件:
vim test.py :
/usr/bin/python
import web
urls=('/(.*)','hello')
app=web.application(urls,globals())
class hello:def GET(self,name):if not name:name='World'return 'Hello'+name+'!'
application=app.wsgifunc()
uwsgi启动方式:
/home/uwsgi/uwsgi --socket 127.0.0.1:9000 --chdir /home/project/maintence.xxx.xxx.com/ -w test
/home/project/maintence.xxx.xxx.com/目录为test.py所在目录
nginx配置:
server {
listen 80;
server_name maintence.xxx.xxx.com;
access_log logs/access_maintence.xxx.xxx.com.log main;
error_log logs/error_maintence.xxx.xxx.com.log warn;
root /home/nginx/html/maintence.xxx.xxx.com;
location / {
include uwsgi_params;
uwsgi_pass 127.0.0.1:9000;
}
}
以上配置可以完成nginx-uwsgi的直连,使用web.py框架
uwsgi可以使用配置文件的方式进行配置:
<whousexml>
<uwsgi id='e-commerce'>
<socket>127.0.0.1:9000</socket>
<chdir>%d/../src</chdir>
<module>test</module>
<master />
<workers>4</workers>
<cpu-affinity>2</cpu-affinity>
<daemonize>%d/../log/uwsgi.log</daemonize>
<pidfile>%d/../log/uwsgi.pid</pidfile>
</uwsgi>
</whousexml>
启动方式:
uwsgi_home='/home/uwsgi'
service_home='/home/project/maintencexxx.xxx.com'
service_id='xxx'
$uwsgi_home/uwsgi --xml $service_home/conf/uwsgi.conf:$service_id
停止:
$uwsgi_home/uwsgi --stop $pid_file
reload:
$uwsgi_home/uwsgi --reload $pid_file
一个简单的启动脚本:
if [ `whoami` != appuser ]
thenecho 'This script need appuser user'exit 1
fi
if [ $# -ne 1 ]; thenecho "Usage:$0 {stop|start|restart|reload}"exit -1
fi
uwsgi_home='/home/uwsgi'
service_home='/home/project/maintence.xxx.xxx.com'
service_id='xxx'
pid_file=$service_home/log/uwsgi.pid
pid=$(cat $pid_file)function start(){$uwsgi_home/uwsgi --xml $service_home/conf/uwsgi.conf:$service_id
}
function stop(){$uwsgi_home/uwsgi --stop $pid_filesleep 3( netstat -tlunp | grep $pid | grep -q uwsgis ) 2> /dev/nullif [ $? == 0 ];thenkill -9 $pidsleep 1fi
}
function reload(){$uwsgi_home/uwsgi --reload $pid_file
}case $1 in stop)stop;;start)start;;restart)stopstart;;reload)reload;;
esac