需要的包
Nginx 配置文件
server
{
listen 80;
server_name t.sh3ll.me;
root /home/wwwroot/web.py;
location /
{
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_script_name;
fastcgi_pass unix:/tmp/pyweb.sock;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
}
location /static/
{
if (-f $request_filename)
{
rewrite ^/static/(.*)$ /static/$1 break;
expires 10d;
}
}
access_log /home/wwwlogs/web.py.log access;
}
Spawn-fcgi
root@localhost:~# cat startSpawn
#!/bin/bash
spawn-fcgi -d /home/wwwroot/web.py/ -f /home/wwwroot/web.py/main.py -s /tmp/pyweb.sock -u www -g www
root@localhost:~# cat stopSpawn
#!/bin/bash
kill `pgrep -f "python /home/wwwroot/web.py/main.py"`
Hello, world!
#!/usr/bin/env 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()
root@localhost:~# ./lnmp start
=========================================================================
Manager for LNMP V1.1 , Written by Licess
=========================================================================
LNMP is a tool to auto-compile & install Nginx+MySQL+PHP on Linux
This script is a tool to Manage status of lnmp
For more information please visit http://www.lnmp.org
Usage: /root/lnmp {start|stop|reload|restart|kill|status}
=========================================================================
Starting LNMP...
Starting nginx... done
Starting php-fpm done
Starting MySQL
.. *
root@localhost:~# ./startSpawn
spawn-fcgi: child spawned successfully: PID: 3370