pythonlinux网站开发_Linux配置Lighttpd+Python+web.py应用

用web.py写了一个app,由于官方网站推荐Lighttpd+fastcgi模式部署,于是实践一把,在Debian Squeeze Linux上成功安装了Lighttpd和基于web.py的应用。

服务器是Debian Sequeeze Linux,首先安装Lighttpd和Python,Python默认版本是2.6:

# apt-get install lighttpd python

然后安装app使用的必要的Python包:

# apt-get install python-setuptools python-flup python-webpy python-mysqldb python-simplejson python-imaging

下一步是配置Lighttpd,由于web.py应用的入口是app.py,所以Lighttpd需要把请求通过fastcgi传给app.py,lighttpd.conf配置如下:

server.modules = (

"mod_access",

"mod_accesslog","mod_alias",

"mod_compress","mod_fastcgi","mod_rewrite",)

server.document-root = "/path/to/app/dir"

server.upload-dirs = ( "/var/cache/lighttpd/uploads" )

server.errorlog = "/var/log/lighttpd/error.log"

server.pid-file = "/var/run/lighttpd.pid"

server.username = "www-data"

server.groupname = "www-data"

index-file.names = ( "index.php", "index.html",

"index.htm", "default.htm",

" index.lighttpd.html" )

url.access-deny = ( "~", ".inc" )

static-file.exclude-extensions = (".py", ".php", ".pl", ".fcgi" )

dir-listing.encoding = "utf-8"

server.dir-listing = "disable"

accesslog.filename = "/var/log/lighttpd/access.log"

compress.cache-dir = "/var/cache/lighttpd/compress/"

compress.filetype = ( "text/css", "text/html" )

fastcgi.server = ( "/app.py" =>(( "socket" =>"/tmp/fastcgi.socket",

"bin-path" =>"/path/to/app/dir/app.py",

"max-procs" =>1,

"check-local" =>"disable"

))

)

url.rewrite-once = (

"^/$" =>"/index.html",

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

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

)

include_shell "/usr/share/lighttpd/create-mime.assign.pl"

主要的改动是红色部分,包括:

配置fastcgi,指向app.py;

配置rewrite,将^/(.*)$指向/app.py/$1;

添加了access log,默认居然没有!

你需要把/path/to/app/dir改为webpy app的所在目录。

最后一步是设置web.py应用的权限,必须确保app.py具有可执行权限。由于fastcgi进程以www-data用户身份运行,最佳配置是将目录owner改为www-data,这样pyc文件才能正确生成:

# chown -R www-data:www-data my-webpy-app

# chmod a+x my-webpy-app/app.py

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值