您的位置:首页 > 理论基础 > 计算机网络

centos下lighttpd web.py环境安装及使用

2014-08-14 00:00 489 查看
摘要: 系统:centos 5.2 python2.4.3, 以 ">" 开头是你要运行的命令, 以 "*" 为注解

以 ">" 开头是你要运行的命令

以 "*" 为注解

系统:centos 5.2 python2.4.3

Step 1: 系统用户 为lighttpd准备

> groupadd -g 80 www

> useradd -g 80 -u 80 -M -s /sbin/nologin www

* -M 不建用户目录

* -s 不能使用shell

Step 2: centos 下安装必要的包

> yum -y install gcc gcc-c++ pcre pcre-devel zlib zlib-devel bzip2 bzip2-devel make autoconf

* pcre 正规表达式

* bzip & zlib 压缩

* make & autoconf 编译安装

Step 3: lighttpd 安装

> wget http://download.lighttpd.net/lighttpd/releases-1.4.x/lighttpd-1.4.26.tar.gz
> tar -zxvf lighttpd-1.4.26.tar.gz

> cd lighttpd-1.4.24

> ./configure && make && make install

> cp doc/rc.lighttpd.redhat /etc/init.d/lighttpd

> cp doc/lighttpd.conf /usr/local/lighttpd.conf

> vim /etc/init.d/lighttpd

* 修改 /usr/sbin/lighttpd 为 /usr/local/sbin/lighttpd

* 修改 /etc/lighttpd/lighttpd 为 /usr/local/etc/lighttpd.conf

执行

> /etc/init.d/lighttpd start

这时访问你的ip有404页面

step 4: web.py安装

*下载 ez_setup.py

> cd ~

> wget peak.telecommunity.com/dist/ez_setup.py

> python ez_setup.py

*执行上条命令后将安装easy_install工具

> easy_install web.py & flup

自动安装web.py 和 flup

* flup传闻是fastcgi的python实理接口类的东东

测试程序:

> vim /home/web/code.py

内容:

#!/usr/bin/env python

import web

urls = (

'/(.*)', 'hello'

)

app = web.application(urls, globals())

class hello:

def GET(self, name):

if not name:

name = 'World'

return 'Hello, ' + name + '!'

if __name__ == "__main__":

app.run()

* 第一行 #!/usr/local/env python 不能少

修改 /usr/local/etc/lighttpd.conf 配置文件

打开 mod_fastcgi 和 mod_rewrite 两个模块

server.document-root = "/home/web/"

fastcgi.server = ( "/code.py" =>

(( "socket" => "/tmp/fastcgi.socket",

"bin-path" => "/home/web/code.py",

"max-procs" => 1

))

)

url.rewrite-once = (

"^/favicon.ico$" => "/static/favicon.ico",

"^/static/(.*)$" => "/static/$1",

"^/(.*)$" => "/code.py/$1"

)

> /etc/init.d/lighttpd restart

重启lighttpd即可
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  centos webpy