LNMP环境源安装web.py
导读
空余时间想测试个web.py,经过多次搜索终于成功运行web.py,过程如下:
安装Web.py
apt-get install python-setuptools easy_install flup easy_install web.py easy_install Jinja2 easy_install MySQL-python
配置Web.py
mkdir -p /home/www/jymmbb
vi /etc/nginx/vhost/jymmbb.conf
server {
listen 80;
server_name dev.jymmbb.com;
root /home/www/jymmbb;
location / {
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_script_name;
fastcgi_pass 127.0.0.1:9002;
}
location /static/ {
if (-f $request_filename) {
rewrite ^/static/(.*)$ /static/$1 break;
}
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ {
expires 30d;
}
location ~ .*\.(js|css)?$ {
expires 12h;
}
access_log /home/log/jymmbb.log access;
}重启Nginx
/etc/init.d/nginx restart
测试Web.py,vi /home/www/jymmbb/main.py
#!/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()添加权限
chown -R www-data:www-data /home/www chmod +x /home/www/jymmbb/main.py
启动
/usr/bin/spawn-fcgi -a 127.0.0.1 -p 9002 -d /home/www/jymmbb -f /home/www/jymmbb/main.py
关闭
kill `pgrep -f "python /home/www/jymmbb/main.py"`
如果需要检查应用程序是否运行,使用
ps aux|grep main.py
评论(0)


