ngnix python 搭建web.py服务

一、安装环境

1)安装web模块

pip install web.py

  2)安装Spawn-fcgi :

wegt http://www.lighttpd.net/download/spawn-fcgi-1.6.3.tar.gz
tar zxvf spawnfcgi1.6.3.tar.gz
cd spawnfcgi1.6.3
./configure prefix=/usr/local/spawnfcgi
make && make install
ln s /usr/local/spawnfcgi/bin/spawnfcgi /usr/bin/

3) 安装flup

wget http://www.saddi.com/software/flup/dist/flup-1.0.2.tar.gz
tar -xzvf flup-1.0.2.tar.gz
cd flup-1.0.2
python setup.py install

 

二、然后创建一个index.py程序

 

 #!/usr/bin/env python
 #-*-coding:utf8-*-
 import web
 #路由配置
 urls = (
 '/', 'Index' #首页,首页指向
 )
 app = web.application(urls, globals())
 class Index:
     def GET(self):
         return 'Hello, world!'
 if __name__ == "__main__":
     web.wsgi.runwsgi = lambda func, addr = None: web.wsgi.runfcgi(func, addr)
     app.run()

添加可执行权限:
chmod +x index.py
 

 

三、通过命令创建spawn-fcgi进程

 

/usr/local/spawn-fcgi/bin/spawn-fcgi -f /home/xxx/develop/instrument/wwwconf/python/index.py -u nobody -g nobody -a 127.0.0.1 -p 9002
提示:spawn-fcgi: child spawned successfully: PID: 31032 说明成功启动
报错:spawn-fcgi: child exited with: 1 加参数 -n 进行调试,查看错误输出

netstat -na | grep 9002 查看端口占用情况

四、配置Nginx

location / {
 include scgi_params;
 fastcgi_param SCRIPT_FILENAME $fastcgi_script_name;
 fastcgi_param PATH_INFO $fastcgi_script_name;
 fastcgi_pass 127.0.0.1:9002;
 fastcgi_param SERVER_ADDR $server_addr;
 fastcgi_param SERVER_PORT $server_port;
 fastcgi_param SERVER_NAME $server_name;
 }

	

You May Also Like

About the Author: daidai5771

发表评论

电子邮件地址不会被公开。 必填项已用*标注