Webpy + Nginx with FastCGI搭建Web.py
这一节讲解的是如何使用Nginx和FastCGI搭建Web.py应用
环境依赖的软件包
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; }}spawn-fcgi -d /path/to/www -f /path/to/www/index.py -a 127.0.0.1 -p 9002
#!/bin/shspawn-fcgi -d /path/to/www -f /path/to/www/index.py -a 127.0.0.1 -p 9002
#!/bin/shkill `pgrep -f "python /path/to/www/index.py"`
#!/usr/bin/env python# -*- coding: utf-8 -*-import weburls = ("/.*", "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()/path/to/nginx/sbin/nginx -s reload
/path/to/nginx/sbin/nginx -s stop