# Rails deployment

**URL:** <https://www.ruby-forum.com/t/rails-deployment/125554>\
**Category:** Rails\
**Created:** [January 10, 2008, 3:04am UTC](https://www.ruby-forum.com/t/rails-deployment/125554 "2008-01-10T03:04:36Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Henry\_Addo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/73ab20/32.png) [@Henry\_Addo](https://www.ruby-forum.com/u/Henry_Addo)\
**Post date:** [January 10, 2008, 3:04am UTC](https://www.ruby-forum.com/t/rails-deployment/125554/1 "2008-01-10T03:04:36Z")

</div>

Currently, I have Apache2 as my frontend and Mongrel as the rails  
application server.  
All request comes into apache but requests for the Rails app are proxied  
(  
mod\_proxy )  
to an instance of the Mongrel web server running on a different port.  
Just  
want to know  
if this is the best practice in terms of robustness, scalability and  
security. Thanks

Henry!

–

> **[Mobile Development Company](https://www.addhen.com)**
>
> Website for Addhen Limited. Highlighting its portfolio and service offerings.

---

<div class="post-metadata">

**Author:** ![Henry\_Addo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/73ab20/32.png) [@Henry\_Addo](https://www.ruby-forum.com/u/Henry_Addo)\
**Post date:** [January 10, 2008, 3:19am UTC](https://www.ruby-forum.com/t/rails-deployment/125554/2 "2008-01-10T03:19:13Z")

</div>

Hey Henry -

On 9-Jan-08, at 9:04 PM, Henry Addo wrote:

> –  
> [Mobile Development Company](http://www.addhen.org/blog)

when you say mod\_proxy, did you mean mod\_proxy\_balancer ?

If so, one of the downside of this solution is that  
mod\_proxy\_balancer won’t skip over busy instances - but will wait for  
it to be free. yuck.

For this reason, and the heaviness of apache, we’ve switched to a  
combo of nginx and haproxy. haproxy is so damn light without the  
previous problem. It can also do some proxying avail in hardware  
balancers.

Ezra (where did I read that?) mentioned that nginx was getting a  
balancer itself - not sure if that’s been addressed

Some of the best minds in rails deployment are on a separate list -  
you might ask there.

[http://groups.google.com/group/rubyonrails-deployment/](http://groups.google.com/group/rubyonrails-deployment/)

Jodi

---

<div class="post-metadata">

**Author:** ![Henry\_Addo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/73ab20/32.png) [@Henry\_Addo](https://www.ruby-forum.com/u/Henry_Addo)\
**Post date:** [January 10, 2008, 3:51pm UTC](https://www.ruby-forum.com/t/rails-deployment/125554/3 "2008-01-10T15:51:44Z")

</div>

I believe Jodi was referring to a fair balancer, not a round-robin one.  
Nginx is testing a fair balancer which will skip over busy backends but  
I  
don’t think there’s a stable build of it.

[http://brainspl.at/articles/2007/11/09/a-fair-proxy-balancer-for-nginx-and-mongrel](http://brainspl.at/articles/2007/11/09/a-fair-proxy-balancer-for-nginx-and-mongrel)

---

<div class="post-metadata">

**Author:** ![Henry\_Addo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/73ab20/32.png) [@Henry\_Addo](https://www.ruby-forum.com/u/Henry_Addo)\
**Post date:** [January 10, 2008, 4:45pm UTC](https://www.ruby-forum.com/t/rails-deployment/125554/4 "2008-01-10T16:45:46Z")

</div>

Ah I see, I had read the brainspl.at article before but hadn’t noted  
that it was not in the stable version of nginx.  
You can get the module here  
[http://wiki.codemongers.com/NginxHttpUpstreamFairModule?highlight=(fair)](http://wiki.codemongers.com/NginxHttpUpstreamFairModule?highlight=%28fair%29)

Going back to Henry’s original question, I have several websites  
running on Apache+Monrgel\_cluster+mod\_proxy\_balancer and they are  
perfectly fine, including one receiving several thousands of hits a  
day. We’re moving most new deploys across to the nginx config as above  
though, Apache is very heavy to use just as a balancer manager.

---

<div class="post-metadata">

**Author:** ![Henry\_Addo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/73ab20/32.png) [@Henry\_Addo](https://www.ruby-forum.com/u/Henry_Addo)\
**Post date:** [January 10, 2008, 1:32pm UTC](https://www.ruby-forum.com/t/rails-deployment/125554/5 "2008-01-10T13:32:46Z")

</div>

Nginx does have a balancer,

here’s a sample nginx install and .conf for ya (ubuntu install

apt-get install -y nginx  
cd /etc/nginx  
mv nginx.conf nginx.conf.orig

user www-data www-data;  
worker\_processes 6;  
pid /var/run/nginx.pid;  
events { worker\_connections 1024; }  
http {  
include /etc/nginx/mime.types;  
default\_type application/octet-stream;  
log\_format main '$remote\_addr - $remote\_user [$time\_local] ’  
'“$request” $status $body\_bytes\_sent  
“$http\_referer” ’  
‘“$http\_user\_agent” “$http\_x\_forwarded\_for”’;  
access\_log /var/log/nginx\_access.log main;  
error\_log /var/log/nginx\_error.log debug;  
sendfile on;  
tcp\_nopush on;  
tcp\_nodelay off;  
gzip on;  
gzip\_http\_version 1.0;  
gzip\_comp\_level 2;  
gzip\_proxied any;  
gzip\_types text/plain text/html text/css application/x-javascript  
text/xml application/xml application/xml+rss text/javascript;  
upstream mongrel {  
server 127.0.0.1:8000;  
server 127.0.0.1:8001;  
server 127.0.0.1:8002;  
}  
server {  
listen 80;  
client\_max\_body\_size 50M;  
# server\_name www.[servername].com [servername].com;  
root /data/www/current/public;  
access\_log /var/log/nginx.servername.access.log main;  
if (-f $document\_root/system/maintenance.html) {  
rewrite ^(._)$ /system/maintenance.html last;  
break;  
}  
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\_max\_temp\_file\_size 0;  
if (-f $request\_filename) {  
break;  
}  
if (-f $request\_filename/index.html) {  
rewrite (._) $1/index.html break;  
}  
if (-f $request\_filename.html) {  
rewrite (.\*) $1.html break;  
}  
if (!-f $request\_filename) {  
proxy\_pass [http://mongrel](http://mongrel);  
break;  
}  
}  
error\_page 500 502 503 504 /500.html;  
location = /500.html {  
root /data/www/current/public;  
}  
}  
}

/etc/init.d/nginx reload

this works great for us.
