Success with Nginx and SwitchPipe

45 views
Skip to first unread message

Lucas Efe

unread,
Feb 7, 2008, 11:11:05 AM2/7/08
to SwitchPipe
I writing only to announce a success on running SwitchPipe through
Nginx.

Thanks for this nice gift to the community. We were needing this. It
was a real pain in tha a** to manage the available ports, plus the
memory consumption.

Right now it goes great!

This is NGINX server config file:
server {
listen 80;
server_name myapp.com;
root /var/apps/myapp.com/current/public;
index index.html index.htm;

location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For
$proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect false;
proxy_read_timeout 300;

if (-f $request_filename/index.html) {
rewrite (.*) $1/index.html break;
}
if (-f $request_filename.html) {
rewrite (.*) $1.html break;
}
if (-f $request_filename.txt) {
rewrite (.*) $1.txt break;
}
# SwitchPipe
proxy_pass http://127.0.0.1:10000/myapp/;

}

error_page 500 502 503 504 /50x.html;
}

It works like a charm.

Best Regards

Lucas Florio
IT Solutions Developer

ChrisR

unread,
Feb 7, 2008, 12:48:33 PM2/7/08
to SwitchPipe
Thanks Lucas Florio

Could you show us the NGINX config file you'd use if you had 3 rails
apps running with switchpipe? I would be greatful!

Thanks
Chris

Peter Cooper

unread,
Feb 8, 2008, 7:58:34 AM2/8/08
to SwitchPipe


On Feb 7, 5:48 pm, ChrisR <EvilGeen...@gmail.com> wrote:
> Thanks Lucas Florio
>
> Could you show us the NGINX config file you'd use if you had 3 rails
> apps running with switchpipe? I would be greatful!

I'm no Nginx expert, but I think you'd just repeat the whole "server"
block three times, then change the particulars in each (the hostname,
the root, and the directory to proxy to, primarily).

Pete

Lucas Florio

unread,
Feb 8, 2008, 8:02:27 AM2/8/08
to Peter Cooper, SwitchPipe
That correct. It's like the Apache's VirtualDomain Configuration, but simpler (in my opinion). My answer was a little more verbosed :S. You have a general configuration file, and one for each virtual_domain/rails_app.

Lucas

Anything else: blog.lucasefe.com.ar

Peter Cooper

unread,
Feb 8, 2008, 1:02:03 PM2/8/08
to SwitchPipe


On Feb 8, 1:02 pm, "Lucas Florio" <lucas...@gmail.com> wrote:
> That correct. It's like the Apache's VirtualDomain Configuration, but
> simpler (in my opinion). My answer was a little more verbosed :S. You have a
> general configuration file, and one for each virtual_domain/rails_app.

By the way, many thanks for posting this! I hadn't got around to
testing on Nginx yet, so this is excellent news :)

Pete

Stuart Saunders

unread,
Feb 10, 2008, 8:41:17 PM2/10/08
to SwitchPipe
I've also had success with the following setup:
nginx 0.5.35
SwitchPipe 1.04
Thin 0.6.3 (using sockets)

Thanks for posting your config.

Stuart
> error_page 500 502 503504 /50x.html;

Peter Cooper

unread,
Feb 11, 2008, 9:31:41 PM2/11/08
to SwitchPipe


On Feb 11, 1:41 am, Stuart Saunders <Stuart.Saund...@gmail.com> wrote:
> I've also had success with the following setup:
> nginx 0.5.35
> SwitchPipe 1.04
> Thin 0.6.3 (using sockets)
>
> Thanks for posting your config.

How's general performance with that setup Stuart? In theory the way
you've rigged it up should be the fastest way possible (with
SwitchPipe at least). Nginx is faster than Apache, Thin is faster than
Mongrel, UNIX sockets are faster than TCP.. :)

Pete

Jason Stirk

unread,
Feb 12, 2008, 12:53:50 AM2/12/08
to SwitchPipe
Hi Lucas, Stuart,

I'm in the process of trying to set up nginx, and it looks to me like
your config file results in SwitchPipe/Mongrel receiving the request
for static content (images, javascripts, etc.). At least, that is what
looks to be happening in my testing.

Are you noticing this too, or is it just something happening with my
setup?

I've tried re-working configs I've found around for nginx and mongrel
to exclude static content from being passed through the proxy, however
I've had no luck. The most obvious snippet based upon the mongrel ones
is something like :

if (-f $request_filename) {
# SwitchPipe
proxy_pass http://127.0.0.1:10000/app_name_here/;
break;
}

However, this throws up errors that:
"proxy_pass" may not have URI part in location given by regular
expression, or inside named location, or inside the "if" statement, or
inside the "limit_except" block in /etc/nginx/nginx.conf:99

I've also tried snippets like the one below in the hope that "break"
will stop the processing and just serve that content, however this
doesn't seem to be how break works.

if (-f $request_filename) {
break;
}

Nginx is serving up static content fine when I comment out the
proxy_pass directive, but I can't seem to work out any way to turn off
the proxy when the file exists in the file system.

I can't say I'm overly familiar with Nginx - do you have any ideas?

Thanks for getting the ball rolling with a Nginx config file though!
Gave me the inspiration to have a play.

On the other side of things, Pete, are there any plans for Switchpipe
to handle passing static content through on it's own, or is that
outside of it's scope? (Just considering other options if there really
isn't a solution to the nginx issue).

Best regards,
Jason Stirk

On Feb 8, 3:11 am, Lucas Efe <lucas...@gmail.com> wrote:
> I writing only to announce a success on running SwitchPipe throughNginx.
>
> Thanks for this nice gift to the community. We were needing this. It
> was a real pain in tha a** to manage the available ports, plus the
> memory consumption.
>
> Right now it goes great!
>
> This isNGINXserver config file:

Lucas Florio

unread,
Feb 12, 2008, 5:53:38 AM2/12/08
to Jason Stirk, SwitchPipe
Hey, Jason, you are right. I checked and is not working properly. I am gonna work on that. The proxy_pass command is not valid inside an if statement. Bummer.
I have to keep doing research. I'll let you all know if I am able to solve the problem...

Regards
Lucas

--
Lucas Florio - IT Solutions Developer
Ruby On Rails Argentina: http://blogs.onrails.com.ar
Anything else: blog.lucasefe.com.ar

Peter Cooper

unread,
Feb 12, 2008, 9:17:45 AM2/12/08
to SwitchPipe


On Feb 12, 5:53 am, Jason Stirk <jst...@gmail.com> wrote:
> On the other side of things, Pete, are there any plans for Switchpipe
> to handle passing static content through on it's own, or is that
> outside of it's scope? (Just considering other options if there really
> isn't a solution to the nginx issue).

I've considered it, but due to the potential permissions / user
issues, it might not be worthwhile. The backend processes can run as
the right user, of course, but SwitchPipe is privileged, and it might
not sit right to have it just slurping up static content as it could
be manipulated into, perhaps, serving things you'd rather it not.

Caching (based on the filesystem modification time), on the other
hand, might be viable and yield great results. That way, we can be
guaranteed of overall security as we'll only serve up things that have
been through SwitchPipe once already (and therefore the backend gets
the overall security responsibility).

Even though I use Apache and mod_rewrite, and therefore Apache is
serving up my static content properly, I have not found the
performance of running static content through the backend /
particularly/ bad, although it is certainly not the best option.

Pete

Aníbal Rojas

unread,
Mar 15, 2008, 8:24:44 AM3/15/08
to SwitchPipe
Jason,

Basically I am new to Nginx and learning, but I think this does the
trick:

location ~* ^.+\.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|
exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js|mov).*?$ {
root /var/www/YOURAPPHERE/current/public;
if (!-f $request_filename) {
proxy_pass http://127.0.0.1:10000/YOURAPPHERE/;
break;
}
}

Best regarsa

--
Aníbal Rojas
http://hasmanydevelopers.com
http://rubycorner.com
http://anibal.rojas.com.ve

On Feb 12, 1:53 am, Jason Stirk <jst...@gmail.com> wrote:
> Hi Lucas, Stuart,
>
> I'm in the process of trying to set up nginx, and it looks to me like
> your config file results in SwitchPipe/Mongrel receiving the request
> for static content (images, javascripts, etc.). At least, that is what
> looks to be happening in my testing.
>
> Are you noticing this too, or is it just something happening with my
> setup?
>
> I've tried re-working configs I've found around for nginx and mongrel
> to exclude static content from being passed through the proxy, however
> I've had no luck. The most obvious snippet based upon the mongrel ones
> is something like :
>
> if (-f $request_filename) {
> # SwitchPipe
> proxy_passhttp://127.0.0.1:10000/app_name_here/;
Reply all
Reply to author
Forward
0 new messages