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

Showing posts with label Merb. Show all posts
Showing posts with label Merb. 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

Saturday, August 23, 2008

Add and remove a remote source from gem 'remote sources''

I was attempting to add a gem and ran into an error I hadn't seen before:

Macintosh:aws-s3 dsparlingimbp$ sudo gem i aws-s3
WARNING: RubyGems 1.2+ index not found for:
http://merbivore.com

RubyGems will revert to legacy indexes degrading performance.
Updating metadata for 63 gems from http://gems.rubyforge.org/
...............................................................
complete
ERROR: could not find gem aws-s3 locally or in a repository


So I tried to update gems:

Macintosh:aws-s3 dsparlingimbp$ sudo gem update --system
Updating RubyGems
WARNING: RubyGems 1.2+ index not found for:
http://merbivore.com

RubyGems will revert to legacy indexes degrading performance.
Updating metadata for 63 gems from http://gems.rubyforge.org/
...............................................................
complete
ERROR: While executing gem ... (Gem::RemoteFetcher::FetchError)
bad response Not Found 404 (http://merbivore.com/Marshal.4.8)

Next I looked the gems environment:

Macintosh:rubygems-1.2.0 dsparlingimbp$ gem env
RubyGems Environment:
- RUBYGEMS VERSION: 1.2.0
- RUBY VERSION: 1.8.6 (2007-03-13 patchlevel 0) [i686-darwin8.8.5]
- INSTALLATION DIRECTORY: /usr/local/lib/ruby/gems/1.8
- RUBY EXECUTABLE: /usr/local/bin/ruby
- EXECUTABLE DIRECTORY: /usr/local/bin
- RUBYGEMS PLATFORMS:
- ruby
- x86-darwin-8
- GEM PATHS:
- /usr/local/lib/ruby/gems/1.8
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :benchmark => false
- :backtrace => false
- :bulk_threshold => 1000
- :sources => ["http://gems.rubyforge.org", "http://merbivore.com"]
- REMOTE SOURCES:
- http://gems.rubyforge.org
- http://merbivore.com

Noticing the issues with Merb (which I recently installed), I removed http://merbivore.com from the list of remote sources:

sudo gem sources -r http://merbivore.com

I went ahead and added github while I was at it:

sudo gem sources -a http://gems.github.com

Checked my gems environment:

Macintosh:rubygems-1.2.0 dsparlingimbp$ gem env
RubyGems Environment:
- RUBYGEMS VERSION: 1.2.0
- RUBY VERSION: 1.8.6 (2007-03-13 patchlevel 0) [i686-darwin8.8.5]
- INSTALLATION DIRECTORY: /usr/local/lib/ruby/gems/1.8
- RUBY EXECUTABLE: /usr/local/bin/ruby
- EXECUTABLE DIRECTORY: /usr/local/bin
- RUBYGEMS PLATFORMS:
- ruby
- x86-darwin-8
- GEM PATHS:
- /usr/local/lib/ruby/gems/1.8
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :benchmark => false
- :backtrace => false
- :bulk_threshold => 1000
- :sources => ["http://gems.rubyforge.org", "http://gems.github.com"]
- REMOTE SOURCES:
- http://gems.rubyforge.org
- http://gems.github.com

Everything looked good, so I tried to install aws-s3 gem again:

Macintosh:rubygems-1.2.0 dsparlingimbp$ sudo gem install aws-s3
Successfully installed aws-s3-0.5.1
1 gem installed
Installing ri documentation for aws-s3-0.5.1...
Installing RDoc documentation for aws-s3-0.5.1...

Et VoilĂ ! C'est si bon...

About Me

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

Labels