Linux配置Lighttpd+Python+web.py应用
2023-02-18 15:28:49 时间
用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
相关文章
- Python图像处理丨5种图像处理特效
- 跟我学Python图像处理丨图像特效处理:毛玻璃、浮雕和油漆特效
- 跟我学Python图像处理丨傅里叶变换之高通滤波和低通滤波
- 跟我学Python图像处理丨带你掌握傅里叶变换原理及实现
- 跟我学Python图像处理丨关于图像金字塔的图像向下取样和向上取样
- Python中的super函数,你熟吗?
- Python图像处理丨带你认识图像量化处理及局部马赛克特效
- Python图像处理丨基于K-Means聚类的图像区域分割
- Python图像处理丨认识图像锐化和边缘提取的4个算子
- 想了解Python中的super 函数么
- 跟我学Python图像处理丨何为图像的灰度非线性变换
- Python代码用在这些地方,其实1行就够了!
- Python图像处理丨图像的灰度线性变换
- Python图像处理丨基于OpenCV和像素处理的图像灰度化处理
- 跟我学Python图像处理丨基于灰度三维图的图像顶帽运算和黑帽运算
- Python图像处理丨带你掌握图像几何变换
- Python图像处理丨如何调用OpenCV绘制直方图
- 学python,怎么能不学习scrapy呢!
- Python图像处理丨两种实现图像形态学转化运算
- Python图像处理丨三种实现图像形态学转化运算模式