How to Configure Swiftiply with Nginx | Webfi...

来源:百度文库 编辑:神马文学网 时间:2024/04/20 03:45:03

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.1cluster_port: 4000daemonize: trueepoll: trueepoll_descriptors: 8192map:- incoming: localhostoutgoing: 127.0.0.1:5000default: truedocroot: /usr/local/httpd/testappredeployable: 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;}