nginx连接uwsgi使用web.py框架构造pythonweb项目
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 :
?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
轉載于:https://my.oschina.net/u/273053/blog/130149
總結
以上是生活随笔為你收集整理的nginx连接uwsgi使用web.py框架构造pythonweb项目的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: datatables 增、删、查、改
- 下一篇: python飞机大战游戏素材_pytho