Tech Tidbits - Ruby, Ruby On Rails, Merb, .Net, Javascript, jQuery, Ajax, CSS...and other random bits and pieces.

Showing posts with label mongrel. Show all posts
Showing posts with label mongrel. Show all posts

Tuesday, November 18, 2008

Nginx, Mongrel, Merb

Quick notes on installing and configuring nginx and running with existing mongrel and Merb app on my MacBookPro.

1) Download and install PCRE (if needed)
http://www.pcre.org/
ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/
ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-7.8.tar.gz

$ ./configure
$ ./make
$ ./make install

2) Download and install nginx:
http://nginx.net/
The latest stable version is nginx-0.6.32, the change log.
http://sysoev.ru/nginx/nginx-0.6.32.tar.gz

$ ./configure
$ ./make
$ ./make install

# Edit nginx.conf file (/usr/local/nginx/conf/nginx.conf)
# Note - based on Ezra's blog post (see notes below)

user nobody;
worker_processes 2;

error_log logs/error.log notice;
pid logs/nginx.pid;

events {
worker_connections 1024;
}

http {
include mime.types;
#include conf/mime.types;
default_type application/octet-stream;

# no sendfile on OSX uncomment
#this if your on linux or bsd
#sendfile on;
tcp_nopush on;

keepalive_timeout 65;
tcp_nodelay on;

upstream mongrel {
server 127.0.0.1:4000;
server 127.0.0.1:4001;
server 127.0.0.1:4002;
}

gzip on;
gzip_min_length 1100;
gzip_buffers 4 8k;
gzip_types text/plain;

server {
listen 80;
#server_name localhost;
root /Users/dsparlingimbp/git/dougsparlingdotcom/public;

access_log off;
rewrite_log on;

location ~ ^/$ {
if (-f /index.html){
rewrite (.*) /index.html last;
}
proxy_pass http://mongrel;
}

location / {
if (!-f $request_filename.html) {
proxy_pass http://mongrel;
}
rewrite (.*) $1.html last;
}

location ~ .html {
root /Users/dsparlingimbp/git/dougsparlingdotcom/public;
}

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 /Users/dsparlingimbp/git/dougsparlingdotcom/public;
}

location / {
proxy_pass http://mongrel;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}

}
}


4) Commands for starting and stopping nginx
start: sudo /usr/local/nginx/sbin/nginx
stop: sudo kill `cat /usr/local/nginx/logs/nginx.pid`

5) Start Mongrel cluster (I'm using 3 Mongrels):
$ merb -c 3
or
$ merb -p 4000 -c 3

6) Resources
http://brainspl.at/articles/2006/08/23/nginx-my-new-favorite-front-end-for-mongrel-cluster
http://articles.slicehost.com/2008/5/13/ubuntu-hardy-installing-nginx-from-source
http://articles.slicehost.com/2008/5/13/ubuntu-hardy-adding-an-nginx-init-script
http://articles.slicehost.com/2008/4/25/ubuntu-hardy-setup-page-1
http://articles.slicehost.com/2008/4/25/ubuntu-hardy-setup-page-2
http://forum.slicehost.com/comments.php?DiscussionID=2179
http://merb.rubyforge.org/files/README.html

Friday, June 8, 2007

Ruby on Rails/Mongrel/Ubuntu

I've been using Ubuntu lately and decided to install Ruby on Rails and Mongrel.


$ sudo apt-get install ruby irb rdoc


Or download the source for the latest version (apt-get installs 1.8.4, but the latest source is 1.8.6):


$ tar zxvf ruby-1.8.6.tar.gz
$ cd ruby-1.8.6
$ ./configure
$ make
$ sudo make install


Once ruby is installed, I typically use Gems if I can.

Download the latest Gems at http://rubyforge.org/frs/?group_id=126 (0.9.4 in this case) and then:


$ tar xzvf rubygems-0.9.4.tgz
$ cd rubygems-0.9.4
$ sudo ruby setup.rb


Install Rails:

sudo gem install rails --include-dependencies


Install Mongrel and Mongrel cluster gem plugin:

sudo gem install mongrel --include-dependencies
sudo gem install mongrel_cluster


Install Apache 2.2

$ tar zxvf httpd-2.2.4.tar.gz
$ cd httpd-2.2.4
$ ./configure \
--prefix=/usr/local/apache \
--enable-rewrite \
--enable-headers \
--enable-ssl \
--enable-proxy \
--with-mpm=prefork
$ make
$ sudo make install


I got this error when running configure:

Configuring Apache Portable Runtime Utility library...

checking for APR-util... yes
configure: error: Cannot use an external APR-util with the bundled APR
make: *** [apache] Error 1


Adding this option fixed the problem:

--with-included-apr


Running Apache with a single Mongrel Instance

$ mongrel_rails start -p 8000 -e production -d


Add to apache conf (httpd.connf)

ServerName hostname.com
ServerAlias www.hostname.com

ProxyPass / http://www.hostname.com:8000/
ProxyPassReverse / http://www.hostname.com:8000/
ProxyPreserveHost on


Restart Apache and it will forward requests for www.hostname.com on port 80 to Mongrel server running on port 8000.

About Me

My photo
Developer (Ruby on Rails, iOS), musician/composer, Buddhist, HSP, Vegan, Aspie.

Labels