uwsgi安装及配置搭档nginx

环境比较奇葩 

Centos5.6  + python 2.7.8

于是有很多问题。

1.安装uwsgi

不能采用网上的方式:

easy_install   -->  pip  -->  安装uwcgi 

提示错误:warning: implicit declaration of function ‘accept4’

各种尝试都有错误

经过查询 系统库不支持:在accept4()用 linux 系统调用是可以启动 2.6.28 ;支持中 glibc 的版本开始 2.10.

参考:http://www.helplib.net/s/linux.die/65_318/man-2-accept4.shtml


只能降低版本,源码安装经测试:

wget http://projects.unbit.it/downloads/uwsgi-1.3.tar.gz
tar xzvf uwsgi-1.3.tar.gz
cd uwsgi-1.3
make
make install 

可以。

妈妈的热泪盈眶啊

2.安装nginx没什么难度掠过

3.配置nginx的uwsgi

server {
    listen       80;
    server_name  uwsgi.xx.com;
    index index.html index.htm index.php;
    root  /opt/wf_stats;
    access_log  logs/stats.access.log  main;
    error_log  logs/stats.error.log;

    location / {
        include  uwsgi_params;
        uwsgi_pass  127.0.0.1:9090;              #必须和uwsgi中的设置一致
        index  index.html index.htm;
        client_max_body_size 55m;
    }
}
这个是vhost 的配置,其他方式的类似


4.wgsgi的配置

[uwsgi]
socket = 127.0.0.1:9090
;主进程
master = true
;多站模式
vhost = true
;多站模式时不设置入口模块和文件
no-stie = true
;子进程数
workers = 2
reload-mercy = 10
;退出、重启时清理文件
vacuum = true
max-requests = 1000
limit-as = 512
buffer-sizi = 30000
wsgi-file = [path]/testUwsgi.py
;pid文件,用于下面的脚本启动、停止该进程
pidfile = /opt/modules/uwsgi/logs/uwsgi9090.pid
daemonize = /opt/modules/uwsgi/logs/uwsgi9090.log


5.wgsig测试

python测试文件:

def application(env, start_response):
        start_response('200 OK', [('Content-Type','text/html')])
        return "Hello World"
保存为testUwsgi.py
不需要nginx的测试

uwsgi --http :9090  --wsgi-file wsgi.py --master --processes 4 --threads 2 


6.wgsig的启动shell

#! /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=uwsgi9090
DAEMON=/usr/local/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: \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

uwsgi9090 start 启动uwsgi



可以了  启动nginx 和  uwsgi 浏览器中访问 
uwsgi.xx.com
 
  


参考:

安装:http://www.cnblogs.com/xiongpq/p/3381069.html

对比:http://developer.51cto.com/art/201010/229615.htm

参数:http://www.cnblogs.com/zhouej/archive/2012/03/25/2379646.html 

bug:http://blog.csdn.net/imphp/article/details/38232133










你可能感兴趣的:(python)