User-Profile-Image
hankin
  • 5
  • 首页
  • 分类
    • Windows
    • Web
    • VoIP
    • Virtualization
    • Trading
    • Smart Home
    • SEO
    • Security
    • Python
    • Program
    • PHP
    • OSX
    • OS
    • OpenSource
    • Nginx
    • MySQL
    • Mood
    • Linux
    • Life
    • Injection
    • Hosting
    • Exploits
    • CDN
  • 页面
    • About
  • 友链
    • 维酷科技
    • Tesra超算网络
Help?

Please contact us on our email for need any support

Support
  • 首页
    首页   ›   OS   ›   Linux   ›   正文
Linux

webpy+nginx+fastcgi使用spawn-fcgi启动fastcgi

2010-09-27 11:13:54
552  0 0

使用spawn-fcgi启动webpy的fastcgi方式,前端是nginx

* 服务器环境:FreeBSD 7.1
* webpy-0.32
* spawn-fcgi v1.6.0
* nginx/0.6.36
* Flup

参照官方网站的例子行不通。

spawn-fcgi没有 -d参数,chroot的参数是-c 使用后会提示stderr输出错误。

修改项目主程序:

1. if __name__==”__main__”:
2. #关掉stderr的输出位置
3. import sys
4. sys.stderr = None
5. #fastcgi的方式运行app
6. web.wsgi.runwsgi = lambda func, addr=None:\
7. web.wsgi.runfcgi(func, addr)
8. app.run()

使用spawn-fcgi启动fastcgi进程:

/usr/local/bin/spawn-fcgi -u www -g www -f /www/zcut/zcut.py -a 127.0.0.1 -p 8032 -F 5 -P /tmp/zcut.pid

参数说明:

-f 指定调用 FastCGI 的进程的执行程序位置,根据系统上所装的 PHP 的情况具体设置
-a 绑定到地址 addr
-p 绑定到端口 port
-F 指定产生的 FastCGI 的进程数
-P 指定产生的进程的 PID 文件路径
-u 和 -g FastCGI 使用什么身份运行

将进程PID保存下来方便关闭进程:

kill `cat /tmp/zcut.pid`

启动后用sockstat -4 查看到类似下列信息,用ps也可以,习惯问题
www python 15274 0 tcp4 127.0.0.1:8032

然后配置nginx指向webpy的fastcgi端口

location / {
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_script_name;
fastcgi_pass 127.0.0.1:8032;
}

配置静态目录:

location /static/ {
if (-f $request_filename) {
rewrite ^/static/(.*)$ /static/$1 break;
}
}

评论 (0)

Click here to cancel reply.

欢迎您 游客  

    ProdigYu
    164文章 10评论 2点赞 82462浏览
    随机文章
    一些IIS环境下的常用组件安装信息
    11年前
    CentOS7\Ubuntu安装VMware Workstation 12
    4年前
    CentOS/Ubuntu/Debian等Linux查看端口占用
    5年前
    使命召唤大逃亡开始安装没有反应
    11个月前
    远程桌面管理器V2.2
    7年前
    Tags
    Apache CentOS CMD DDOS Debian DNS FastCGI Google IIS IP iptables Linux Mac MySQL Nginx Opensource PHP Python Skill Spawn-FCGI SSH Ubuntu Vim VMware VPN web.py Windows 删除 命令 命令提示符 安装 开源 技巧 插件 漏洞 百度 系统 组件 终端 缓存 网络电话 脚本 自建 详解 错误
    Meta
    • Log in
    • Entries feed
    • Comments feed
    • WordPress.org
    Copyright © 2021
    Designed by hankin
    主页
    页面
    • About
    博主
    ProdigYu 管理员
    Something about myself
    164 文章 10 评论 82462 浏览
    测试
    测试