上一篇中有关于安装nginx、python、uwsgi的过程,这里不再重述。下面是有关在具体布署中的一些过程和问题处理
一、因为用到了bs4(BeautifulSoup)pastelxml所以这些先安装,pip安装即可
二、nginx端口更改为了8001,防止与原来已经存在的apache服务器冲突,uwsgi使用了8010的端口。其中在测试的时候发现返回为200 ok,但没有输出内容,后来网上看到要注意python的版本,我用的是python3。
# test.py def application(env, start_response): start_response('200 OK', [('Content-Type','text/html')]) return [b"Hello World"] # python3 #return ["Hello World"] # python2
三、测试uwsgi的时候用
uwsgi --http :8001 --wsgi-file test.py
但实际使用中要开机启动,所以参考了http://www.cnblogs.com/xiongpq/p/3381069.html,
#! /bin/sh # chkconfig: 2345 55 25 # Description: Startup script for uwsgi webserver on Debian. Place in /etc/init.d and # run 'update-rc.d -f uwsgi defaults', or use the appropriate command on your # distro. For CentOS/Redhat run: 'chkconfig --add uwsgi' ### BEGIN INIT INFO # Provides: uwsgi # Required-Start: $all # Required-Stop: $all # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: starts the uwsgi web server # Description: starts uwsgi using start-stop-daemon ### END INIT INFO # Author: licess # website: http://lnmp.org PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin DESC="uwsgi daemon" NAME=uwsgi8010 DAEMON=/usr/bin/uwsgi //注意你的安装位置 CONFIGFILE=/etc/$NAME.ini PIDFILE=/var/run/$NAME.pid SCRIPTNAME=/etc/init.d/$NAME set -e [ -x "$DAEMON" ] || exit 0 do_start() { $DAEMON $CONFIGFILE || echo -n "uwsgi already running" } do_stop() { $DAEMON --stop $PIDFILE || echo -n "uwsgi not running" rm -f $PIDFILE echo "$DAEMON STOPED." } do_reload() { $DAEMON --reload $PIDFILE || echo -n "uwsgi can't reload" } do_status() { ps aux|grep $DAEMON } case "$1" in status) echo -en "Status $NAME: " do_status ;; start) echo -en "Starting $NAME: " do_start ;; stop) echo -en "Stopping $NAME: " do_stop ;; reload|graceful) echo -en "Reloading $NAME: " do_reload ;; *) echo "Usage: $SCRIPTNAME {start|stop|reload}" >&2 exit 3 ;; esac exit 0 uwsgi8010
终端执行
-- 添加服务 chkconfig --add uwsgi9090 -- 设置开机启动 chkconfig uwsgi9090 on
四、本人接口的存放位置放在了/var/www目录下,包括uwsgi8010.ini和日志文件uwsgi8010.log
别外要注意的是
- paste.request.parse_querystring(environ)
- environ返回的是list,里面的参数是tulp,注意读取的方法和顺序