在上一篇文章linux下nginx+python+fastcgi部署总结(django版)中,我们部署了nginx+django+fastcgi的环境,这次我们来部署一下nginx+web.py+fastcgi。
其实web.py上的官方网站已经说的比较清楚了,原文如下:
http://webpy.org/cookbook/fastcgi-nginx
这里主要讲一下一些原文没有照顾到的地方。
一.安装依赖
spawn-cgi
flup
二.配置nginx
在server配置项下增加
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
| location / { #这两种方法都可以,只不过spawn-cgi启动的方法不同 #fastcgi_pass 127.0.0.1:9002; fastcgi_pass unix:webpy.sock;
fastcgi_param REQUEST_METHOD $request_method; fastcgi_param QUERY_STRING $query_string; fastcgi_param CONTENT_TYPE $content_type; fastcgi_param CONTENT_LENGTH $content_length; fastcgi_param GATEWAY_INTERFACE CGI/1.1; fastcgi_param SERVER_SOFTWARE nginx/$nginx_version; fastcgi_param REMOTE_ADDR $remote_addr; fastcgi_param REMOTE_PORT $remote_port; fastcgi_param SERVER_ADDR $server_addr; fastcgi_param SERVER_PORT $server_port; fastcgi_param SERVER_NAME $server_name; fastcgi_param SERVER_PROTOCOL $server_protocol; fastcgi_param SCRIPT_FILENAME $fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_script_name; }
|
三.一个简单的index.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
| #!/usr/bin/python # -*- coding: utf-8 -*- import web
urls = ("/.*", "hello") app = web.application(urls, globals()) class hello:
def GET(self):
return 'Hello, world!' if __name__ == "__main__":
web.wsgi.runwsgi = lambda func, addr=None: web.wsgi.runfcgi(func, addr) app.run()
|
并执行:
四.启动web.py
启动:
1
2
| #spawn-fcgi -P `pwd`/webpy.pid -f /home/dantezhu/htdocs/ngx_web/index.py -a 127.0.0.1 -p 9002 & spawn-fcgi -P `pwd`/webpy.pid -f /home/dantezhu/htdocs/ngx_web/index.py -s /home/dantezhu/nginx/sbin/webpy.sock &
|
停止:
五.启动nginx
与上一篇文章一样,这里不再赘述。
六.加入到rc.local中,自动启动
1
2
3
| /home/dantezhu/nginx/sbin/start.shsudo -u dantezhu /home/dantezhu/htdocs/ngx_django/mysite/start.shsudo -u dantezhu /home/dantezhu/htdocs/ngx_web/start.sh
|
OK,就是这样啦~