本站首页    管理页面    写新日志    退出


«October 2025»
1234
567891011
12131415161718
19202122232425
262728293031


公告
 本博客在此声明所有文章均为转摘,只做资料收集使用。

我的分类(专题)

日志更新

最新评论

留言板

链接

Blog信息
blog名称:
日志总数:1304
评论数量:2242
留言数量:5
访问次数:7629597
建立时间:2006年5月29日




[Ruby on Rails]Configuring pound with lighttpd and mongrel.
软件技术

lhwork 发表于 2007/2/7 16:16:41

This article describes how to configure pound to use lighttpd to serve the static parts of your rails application and mongrel to serve your dynamic content. I’ve tried several different deployment options for rails over the last few months. My preferred setup at the moment it to use pound as a reverse proxy/load balancer, proxying to lighttpd for static requests such as images, css and javascript files, and proxying to a cluster of mongrels for dynamic requests. This setup is described in detail by Rob Orsini. Rob’s article contains most of the details for this setup. The only differences are in the pound configuration shown below. The idea is that all requests are received by pound and pound decides whether to pass on the request to lighttpd or one of the mongrel cluster. Lighttpd serves the static files since it is extremely fast for serving static content and mongrel handles the dynamic requests. Here is an example pound configuration file for this setup. This assumes we have lighttpd running on port 8000 and 3 mongrel servers running on ports 9000, 9001 and 9002.User "www" Group "www" LogLevel 2 Alive 30 ListenHTTP Address 123.234.345.123 Port 80 End Service URL "/(images|stylesheets|javascripts)/" BackEnd Address 127.0.0.1 Port 8000 End Session Type BASIC TTL 300 End End Service # Catch All BackEnd Address 127.0.0.1 Port 9000 End BackEnd Address 127.0.0.1 Port 9001 End BackEnd Address 127.0.0.1 Port 9002 End Session Type BASIC TTL 300 End End We define two services - the first is is the lighttd server, the second consists of the 3 mongrel servers. The first services catches all requests for items in your images, stylesheets or javascripts directory. It matches urls that contain /images/ or /stylesheets/ or /javascripts/. These requests are all served by lighttpd. Requests that don’t match one of these are served by the default service. This is our cluster of 3 mongrel processes running on ports 9000, 9001 and 9002. Pound will send each dynamic request to one of these servers. A note on matching urls You may need to change the url matching criteria depending on your application and setup. I initially used a configuration similar to the image server example from the pound man page:# Images server(s) Service URL ".*.(jpg|gif|png|js|css|jpeg|html|txt)" BackEnd Address 127.0.0.1 Port 8000 End End This seemed to work ok. But after a while I started seeing strange page-not-found errors. It turned out that the above configuration was matching the suffix tokens occuring anywhere in the url, and didn’t care whether there was a dot before it. So pound was routing the url /profile/giffo to lighttpd because it contains 'gif' instead of sending it to one of the mongrel servers. Escaping the dot and adding the $ at the end fixed this problem - now it only matches urls ending in .gif Here is the updated configuration:Service URL "\.(jpg|gif|png|js|css|jpeg|html|txt)$" BackEnd Address 127.0.0.1 Port 8000 End End This matches urls that end in .gif, .png etc. For rails applications, this has a problem because rails appends a string parameter to static resources. E.g. prototype.js gets included as something such as "/javascripts/prototype.js?1157650839". These requests won’t be matched by this rule. You could use something like this to serve static files from location outside your rails root. But for rails applications it’s probably easiest to match against the names of the directories in your applications public folder as shown in the configuration file above.


阅读全文(2501) | 回复(0) | 编辑 | 精华
 



发表评论:
昵称:
密码:
主页:
标题:
验证码:  (不区分大小写,请仔细填写,输错需重写评论内容!)



站点首页 | 联系我们 | 博客注册 | 博客登陆

Sponsored By W3CHINA
W3CHINA Blog 0.8 Processed in 0.063 second(s), page refreshed 144806792 times.
《全国人大常委会关于维护互联网安全的决定》  《计算机信息网络国际联网安全保护管理办法》
苏ICP备05006046号