1.准备环境

CentOs  6.3

nginx-1.4.2.tar.gz            http://nginx.org/download/nginx-1.4.2.tar.gz

openssl-1.0.1c.tar.gz       http://www.openssl.org/source/openssl-1.0.1c.tar.gz

pcre-8.34.tar.gz              ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.34.tar.gz

spawn-fcgi-1.6.4.tar.gz    http://download.lighttpd.net/spawn-fcgi/releases-1.6.x/spawn-fcgi-1.6.4.tar.gz

zlib-1.2.8.tar.gz              http://zlib.net/zlib-1.2.8.tar.gz

flup-1.0.2.tar.gz              http://www.saddi.com/software/flup/dist/flup-1.0.2.tar.gz

yum -y install gcc automake autoconf libtool make

yum install gcc gcc-c++   python-setuptools  python-pip

pip  install  web.py

2.安装

2.1 zlib安装

tar zxvf zlib-1.2..tar.gz

cd zlib-1.2.

./configure

make && make  install

2.2 pcre安装

tar zxvf pcre-8.34.tar.gz

cd pcre-8.34

./configure 
make && make install

2.3 nginx安装

tar zxvf nginx-1.4..tar.gz 

cd nginx-1.4.

./configure --sbin-path=/usr/local/nginx/nginx \

--conf-path=/usr/local/nginx/nginx.conf \

--pid-path=/usr/local/nginx/nginx.pid \

--with-http_ssl_module  \

--with-pcre=../pcre-8.34 --with-zlib=../zlib-1.2. --with-openssl=../openssl-1.0.1c

make && make install

3.测试nginx

启动:/usr/local/nginx/nginx

访问: http://x.x.x.x

出现如下表示nginx安装正常

暂时先关闭nginx,以下是关闭nginx脚本

#!/bin/sh
#
# nginx - this script starts and stops the nginx daemin
#
# chkconfig: -
# description: Nginx is an HTTP(S) server, HTTP(S) reverse \
# proxy and IMAP/POP3 proxy server
# processname: nginx
# config: /usr/local/nginx/conf/nginx.conf
# pidfile: /usr/local/nginx/logs/nginx.pid # Source function library.
. /etc/rc.d/init.d/functions # Source networking configuration.
. /etc/sysconfig/network # Check that networking is up.
[ "$NETWORKING" = "no" ] && exit nginx="/usr/local/nginx/nginx"
prog=$(basename $nginx) NGINX_CONF_FILE="/usr/local/nginx/nginx.conf" lockfile=/var/lock/subsys/nginx start() {
[ -x $nginx ] || exit
[ -f $NGINX_CONF_FILE ] || exit
echo -n $"Starting $prog: "
daemon $nginx -c $NGINX_CONF_FILE
retval=$?
echo
[ $retval -eq ] && touch $lockfile
return $retval
} stop() {
echo -n $"Stopping $prog: "
killproc $prog -QUIT
retval=$?
echo
[ $retval -eq ] && rm -f $lockfile
return $retval
} restart() {
configtest || return $?
stop
start
} reload() {
configtest || return $?
echo -n $"Reloading $prog: "
killproc $nginx -HUP
RETVAL=$?
echo
} force_reload() {
restart
} configtest() {
$nginx -t -c $NGINX_CONF_FILE
} rh_status() {
status $prog
} rh_status_q() {
rh_status >/dev/null >&
} case "$1" in
start)
rh_status_q && exit
$
;;
stop)
rh_status_q || exit
$
;;
restart|configtest)
$
;;
reload)
rh_status_q || exit
$
;;
force-reload)
force_reload
;;
status)
rh_status
;;
condrestart|try-restart)
rh_status_q || exit
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
exit
esac

4.安装fcgi及flup

tar zxvf spawn-fcgi-1.6..tar.gz

cd spawn-fcgi-1.6.

./configure

make && make install
tar zxvf flup-1.0..tar.gz

cd flup-1.0.

python setup.py  install

5.配置nginx及webpy应用

vim  /usr/local/nginx/nginx.conf

worker_processes  ;
events {
worker_connections ;
} http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout ;
server {
listen ;
server_name localhost;
root /data/www/;
access_log /data/log/test.access.log; location / {
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $fastcgi_script_name; # [1]
fastcgi_param PATH_INFO $fastcgi_script_name; # [2]
fastcgi_pass 127.0.0.1:9002;
} location /static/ { #配置静态文件路径访问
if (-f $request_filename){
rewrite ^/static/(.*)$ /static/$1 break;
} } error_page /50x.html;
location = /50x.html {
root html;
}
}
}

web.py应用加上以下内容server.py

if __name__ == "__main__":
  web.wsgi.runwsgi = lambda func, addr=None: web.wsgi.runfcgi(func, addr)

      app.run()

同时配置一个启动脚本

[root@roddy www]# vim start.sh
#!/bin/sh
spawn-fcgi -d /data/www -f /data/www/server.py -a 127.0.0.1 -p

启动fcgi及nginx

[root@roddy www]# sh start.sh 

[root@roddy www]# /etc/init.d/nginx  start

检查监听端口

[root@roddy www]# netstat -nlpt | egrep "9002|80"
tcp 127.0.0.1: 0.0.0.0:* LISTEN /python
tcp 0.0.0.0: 0.0.0.0:* LISTEN /nginx
[root@roddy www]#

现在即可输入http://x.x.x.x访问你的应用吧

webpy + nginx + fastcgi 构建python应用的更多相关文章

  1. nginx上用fastcgi配置python环境

    费了2天的功夫,翻阅了无数的中文.英文资料,终于搞定.写下此文留待以后翻阅用      本文环境,centOS 5.4 ,Nignx-0.8.49, Python 2.6.5   ========== ...

  2. Nginx + FastCGI 程序(C/C++) 搭建高性能web service的Demo及部署发布

       FastCGI编程包括四部分:初始化编码.接收请求循环.响应内容.响应结束循环. FCGX_Request request; FCGX_Init(); ); FCGX_InitRequest(& ...

  3. nginx+fastcgi+c/cpp

    参考:http://github.tiankonguse.com/blog/2015/01/19/cgi-nginx-three/ 跟着做了一遍,然后根据记忆写的,不清楚有没错漏步骤,希望多多评论多多 ...

  4. 使用Nginx+CppCMS构建高效Web应用服务器

    使用Nginx+CppCMS构建高效Web应用服务器 1:Why当前,越来越多的网站使用了各种框架,大部分框架使用了脚本语言.半编译语言等.比如Java.Python.Php.C#.NET等.这些框架 ...

  5. windows+nginx+iis+redis+Task.MainForm构建分布式架构 之 (nginx+iis构建服务集群)

    本次要分享的是利用windows+nginx+iis+redis+Task.MainForm组建分布式架构,由标题就能看出此内容不是一篇分享文章能说完的,所以我打算分几篇分享文章来讲解,一步一步实现分 ...

  6. Nginx+FastCGI运行原理

    Nginx不支持对外部程序的直接调用或者解析,所有的外部程序(包括PHP)必须通过FastCGI接口来调用.FastCGI接口在Linux下是socket(这个socket可以是文件socket,也可 ...

  7. Python黑帽编程1.2 基于VS Code构建Python开发环境

    Python黑帽编程1.2  基于VS Code构建Python开发环境 0.1  本系列教程说明 本系列教程,采用的大纲母本为<Understanding Network Hacks Atta ...

  8. 记录一次自己对nginx+fastcgi(fpm)+mysql压力测试结果

    nginx + fastcgi(fpm) 压力测试: CentOS release 5.9 16核12G内存 静态页面: 并发1000,压测200秒,测试结果: 系统最大负载5.47 成功响应: 25 ...

  9. nginx上部署python web

    nginx上部署python web http://uwsgi-docs.readthedocs.io/en/latest/tutorials/Django_and_nginx.html

随机推荐

  1. 数学期望和概率DP题目泛做(为了对应AD的课件)

    题1: Uva 1636 Headshot 题目大意: 给出一个000111序列,注意实际上是环状的.问是0出现的概率大,还是当前是0,下一个还是0的概率大. 问题比较简单,注意比较大小: A/C & ...

  2. Ubuntu14.04上安装tftpd服务

    首先sudo apt-get install tftpd-hpa,  tftp-hpa 然后sudo vim /etc/default/tftpd-hpa 配置文件如下 TFTP_USERNAME=& ...

  3. CSS样式中,background-image 背景图片居中显示并且在不同屏幕分辨率下始终居中

    body {   margin-top:0px; margin-right:0px;   margin-bottom:0px;   margin-left:0px;   background-colo ...

  4. http://codepen.io/zhou-yg/pen/NqgPmg 在线编辑器

    http://codepen.io/zhou-yg/pen/NqgPmg          在线编辑器

  5. python3.4+selenium爬58同城(一)

    爬取http://bj.58.com/pbdn/0/pn2/中除转转.推广商品以外的产品信息,因为转转和推广的详情信息不规范,需要另外写一个方法存放,后期补上,详情页如下 这周学习了爬虫,但是遇到一些 ...

  6. UPX和WinUpack压缩壳的使用和脱法 - 脱壳篇06

    UPX和WinUpack压缩壳的使用和脱法 - 脱壳篇06 让编程改变世界 Change the world by program 今天小甲鱼给大家介绍两款压缩壳:UPX和WinUpack. UPX是 ...

  7. wordpress教程之the_author_meta()显示用户的信息

    描述 模板标签函数the_author_meta可以显示用户数据.如果该函数在文章主循环(Loop)中,则不必指定作者的ID值,标签所显示的就是当前文章作者的内容.如果在主循环(Loop)外,则需要指 ...

  8. UFI命令格式里SCSI指令

    有三种字长命令:6位.10位.12位,一般Windows下用12位. 在UFI 命令格式里SCSI指令用到如下: 指令代码 指令名称 说明 04h Format Unit 格式化存储单元 12h In ...

  9. linux下类似Bus Hound的工具

    0推荐在linux大家有时候需要调试usb接口的串口消息,但是没有类似于windows下的bus hound工具,感觉比较痛苦,其实linux内核提供了usbmon这个工具,可以收集串口信息. 1.准 ...

  10. WPF笔记(1.10 绘图)——Hello,WPF!

    原文:WPF笔记(1.10 绘图)--Hello,WPF! 书中的代码语法过时了,改写为以下(测试通过):         <Button>            <Button.L ...