Linux 上利用Nginx代理uWSGI处理Flask Web应用(2)

以.ini格式为uwsgi启动配置文件(还有xml,json,等多种格式),这样就不用在命令行输入一大堆命令了,用uwsgi命令启动,后面可以创建uwsgi启动脚本,加入到系统服务

在项目的目录中,创建uwsgi.ini:

[root@linuxidc webtest]# cat uwsgi.ini [uwsgi] uid = nginx gid = nginx socket = 127.0.0.1:8000 master = true vhost = true workers = 8 reload-mercy = 10 vacuum = true max-requests = 10000 limit-as = 1024 buffer-sizi = 3000 pidfile = /var/run/uwsgi.pid daemonize = /var/log/uwsgi/uwsgi.log chdir = /usr/local/webtest module = wsgi chmod-socket = 660 enable-threads = true

保存并退出。

大致的解释下:

uid 、gid :以哪个用户、组启动服务

socket:监听的ip及端口

master: 启动主进程

workes:服务器启动的进程数

reload-mercy:平滑的重启

pidfile :启动时的pid 文件。

daemonize :启动日志

module :web应用的入口模块名称

enable-threads : 启用线程模式

8)        创建开机系统启动脚本文件,名字为uwsgid。

 

#! /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: uwsgid # 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=uwsgi DAEMON=/usr/bin/uwsgi CONFIGFILE=/usr/local/webtest/$NAME.ini PIDFILE=/var/run/$NAME.pid SCRIPTNAME=/etc/init.d/uwsgid 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 | grep -v grep } case "$1" in status) echo -en "Status $NAME: \n" do_status ;; start) echo -en "Starting $NAME: \n" do_start ;; stop) echo -en "Stopping $NAME: \n" do_stop ;; reload|graceful) echo -en "Reloading $NAME: \n" do_reload ;; *) echo "Usage: $SCRIPTNAME {start|stop|reload}" >&2 exit 3 ;; esac exit 0

uwsgid

创建完成后,赋予执行权限,加入开机启动

[root@linuxidc ~]# chmod +x /etc/init.d/uwsgid [root@linuxidc ~]# chkconfig --add uwsgid
[root@linuxidc ~]# chkconfig --level 2345 uwsgid on

检查下

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/34ca8a682fafc0d0ab14cf064ae6a941.html