LNMP环境源安装web.py

空余时间想测试个web.py,经过多次搜索终于成功运行web.py,过程如下:
在已有LNMP环境下(如果还没有装好环境,可参考Debian 源安装 NGINX+PHP+MYSQL

安装Web.py

1
2
3
4
5
apt-get install python-setuptools
easy_install flup
easy_install web.py
easy_install Jinja2
easy_install MySQL-python

配置Web.py

1
mkdir -p /home/www/jymmbb


vi /etc/nginx/vhost/jymmbb.conf

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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

1
/etc/init.d/nginx restart

测试Web.py
vi /home/www/jymmbb/main.py

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#!/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()

添加权限

1
2
chown -R www-data:www-data /home/www
chmod +x /home/www/jymmbb/main.py

启动

1
/usr/bin/spawn-fcgi -a 127.0.0.1 -p 9002 -d /home/www/jymmbb -f /home/www/jymmbb/main.py

关闭

1
kill `pgrep -f "python /home/www/jymmbb/main.py"`

如果需要检查应用程序是否运行,使用

1
ps aux|grep main.py

发表评论

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