nginx plus embedded ruby - how?

Apologies if this is a dumb question, but I'm a recent convert to nginx, after many years hosting my sites using Apache and I'm still finding my way around:

Can someone tell me the best way to serve up embedded ruby [ie. using .erb or .rhtml] using nginx?

I was hoping there'd be some similar ruby-esque equivlaent to PHP-FPM, which I'm using to serve up my PHP files via nginx [as described here: [url=http://interfacelab.com/nginx-php-fpm-apc-awesome]http://interfacelab.com/nginx-php-fpm-apc-awesome ], but I'm not having any luck.

I think [but I'm not completely sure!] that using phusion passenger [ [url=http://www.modrails.com]http://www.modrails.com ], to build a complete nginx/RoR application serving stack, might allow me to just use it to serve embedded ruby, but it seems like a bit of overkill, when all I want to do is use ruby for a bit of form-validation and the occasional bit of dynamic text generation inside HTML.

Anyone able to help?

1 Reply

So what it comes down to is the need to pass requests off to your ruby site. To do this, the ruby site will need to run on a local address and port, and then you can proxy_pass requests to the ruby site.

I recommend using Rack to host your sites directly, or using some very thin abstraction on top of Rack (i.e. Sinatra). Then you can use Phusion Passenger to host the Rack application. Phusion Passenger has two options:

1.) Compile a module directly into nginx. This works great if you're doing a source-based install of nginx. The downside here, though, is that you're locked into a single version of Ruby, so tools like RVM are basically useless.

2.) Run the standalone passenger webserver (which is actually a mini nginx install that listens on a local socket). You can do this by running "gem install passenger", and then "passenger start" within your application's main directory. The advantage here is that you can use whatever version of Ruby you want, and it plays very nicely with RVM's gemsets. The downside is obviously that you have another mini nginx install, but I really haven't ever encountered a problem with this setup. Nginx uses so little memory and CPU that it really is negligible in my opinion.

TLDR:

1.) Make your application Rack compliant (Sinatra is awesome for this!)

2.) Use Phusion Passenger to serve your app on a local TCP or Unix socket (other options for this are unicorn or thin, but most people tend to prefer passenger).

3.) If you decided to use passenger standalone, configure your main nginx install to proxy_pass requests to the passenger standalone. If you compiled passenger support directly into your main nginx install, this step is not required.

My recommendation: use passenger standalone over a Unix socket. I run a few Rails sites on my 512 with no problems.

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct