Deployment
Blog Posts
- Phusion Passenger now supports Merb Check out the Phusion Passenger page for more info.
- Nginx and Mongrel Merb – Yes, it’s outdated but that has a great nginx configuration file.
- Soar with Merb
- Starter guide for getting configured on Fedora 8 – Updated 4/13/08
- Merb Server Management
Phusion Passenger.
See separate page for Phusion Passenger. In 2.0 it supports Rack-based frameworks so you can use it with Merb.
Choosing An Application Server
- Due its being threaded, Mongrel is still the king as a general purpose application server.
- Use of an evented server (Thin, Ebb, Evented Mongrel) is only a viable option for applications that have very fast response times for every action (i.e. an API that serves JSON) as a long running action will queue any subsequent requests until its completion.
Booting Your Production Application
merb -e production -c 4 --port 9000will start four Mongrels on ports 9000, 9001, 9002 and 9003 in production mode.
This can be done programatically with Capistrano:
# config/deploy.rb
set :adapter, 'mongrel' # or 'thin'
set :start_port, 4000
set :processes, 4
set :log_path, "#{shared_path}/log/production.log"
namespace :deploy do
desc "Start Merb Instances"
task :start do
run "merb -a #{adapter} -e production -c #{processes} --port #{start_port} -m #{current_path} -L #{log_path}"
end
desc "Stop Merb Instances"
task :stop do
run "cd #{current_path} && merb -a #{adapter} -k all"
end
desc 'Custom restart task for Merb'
task :restart, :roles => :app do
deploy.stop
deploy.start
end
end
Using Nginx
Install Nginx
In Debian
$ sudo apt-get install nginx
In Archlinux
Make sure you have the community repo configured in your /etc/pacman.conf
pacman -S nginx
Once Nginx has been installed, the configuration for the merb application needs to be applied.
Configuring Nginx
This has been split up into the general configuration and the specific virtual host for the application. First, the general configuration as shown below:
# /etc/nginx/nginx.conf
user www-data www-data; #chowned this user/group
worker_processes 4;
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
access_log /var/log/nginx/access.log;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
tcp_nodelay on;
gzip on;
upstream proxy_server {
server 127.0.0.1:4000;
server 127.0.0.1:4001;
server 127.0.0.1:4002;
server 127.0.0.1:4003;
}
# virtual configs
include /etc/nginx/conf/vhosts/app.conf;
}
and then the specific virtual configuration file:
# /etc/nginx/conf/vhosts/app.conf
server {
listen 80;
client_max_body_size 50M;
server_name www.myservername.com;
root /path/to/app/current/public;
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://proxy_server;
break;
} }
error_page 500 502 503 504 /500.html;
location = /500.html {
root /path/to/app/current/public;
}
}
Configuring for a shared host
If you want to run your merb app on a /prefix on your server, edit init.rb and add c[:path_prefix] = '/prefix' within the Merb::Config.use do |c| block.