分享

How to Configure Swiftiply with Nginx | Webfi...

 shaobin0604@163.com 2008-12-10

How to Configure Swiftiply with Nginx

Swiftiply is a proxying solution which boosts the performance of Ruby on Rails and Merb apps. One configuration allows you to use Swiftiply as an HTTP proxy, leveraging what are known as “Swiftiplied” Mongrels. These patched Mongrels become clients of the Swiftiply server and maintain a persistent connection, which is a reversal of the usual proxying solution (think Pound, Squid, etc.).

Nginx is a lightweight, fast HTTP server, which is gaining popularity. Nginx is setup as a reverse proxy to Swiftiply, which in turn has a direct connection to multiple Mongrel processes.

So when an HTTP request comes in, the pipeline looks like this…

HTTP request -> Nginx -> Swiftiply -> Mongrels

To successfully make Nginx and Swiftiply play nicely with one another, the configuration is fairly straightforward.

In nginx.conf, the cluster consists of ONE server entry:

upstream mongrel_test_cluster {
server 127.0.0.1:4000;
}

This may appear strange at first glance but really, what you’re telling Nginx is to proxy all requests to the same port being listened on by Swiftiply, which in turn, communicates with the Mongrels.

In swiftiply.yml:

cluster_address: 127.0.0.1
cluster_port: 4000
daemonize: true
epoll: true
epoll_descriptors: 8192
map:
- incoming: localhost
outgoing: 127.0.0.1:5000
default: true
docroot: /usr/local/httpd/testapp
redeployable: true

Swiftiply is listening on port 4000 and passing requests to port 5000 (to the “Swiftiplied” Mongrels).

To transform your Mongrel into a Swiftiplied Mongrel, just add the following line to your app’s config file:

require 'swiftcore/swiftiplied_mongrel'

Then, it’s as simple as firing up your Swiftiplied Mongrels and the Swiftiply server (both are covered in more detail in the Swiftcore docs), and Nginx.

The other Swiftiply configuration, using “Evented” Mongrels, is much simpler and does not use the Swiftiply server.

Just add this include to your Web application’s configuration file:

require 'swiftcore/swiftiplied_mongrel'

and configure Nginx as you would with a standard set of Mongrels.

upstream mongrel_test_cluster {
server 127.0.0.1:4000;
server 127.0.0.1:4001;
server 127.0.0.1:4002;
server 127.0.0.1:4003;
}

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多