Ubuntu 11.XX + Nginx + Thin + Rails 3: A HOW-TO
Updated on: Dec. 20th, 2011
A step-by-step guide for getting Ruby on Rails (1.9.x/3.x) working on Ubuntu 11.x and Nginx.
Basics
Update the system:
Install the essentials: Build system, NodeJS, Nginx
|
1 2 3 4 5 6 7 8 |
# Build essentials
sudo apt-get install build-essential bison openssl libreadline5 libreadline-gplv2-dev curl git-core zlib1g zlib1g-dev libssl-dev libsqlite3-0 libsqlite3-dev sqlite3 libxml2-dev libmysqlclient-dev
# NodeJS
sudo apt-get install nodejs
# Nginx
sudo apt-get install nginx
# Links (for testing)
sudo apt-get install links |
Security
Add a bit of security:
|
1 2 3 4 5 6 7 8 |
# Install Uncomplicated Firewall
apt-get install ufw
# Permit incoming ports TCP 80 (http), and 443 (https)
sudo ufw add 'Nginx Full'
# Permit incoming port TCP 22 (ssh)
sudo ufw add 'OpenSSH'
# Enable UFW (fingers crossed)
sudo ufw enable |
Ruby
Install Ruby using RVM.
|
1 |
sudo bash -s stable < <(curl -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer ) |
NOTE: I recommend relaunching your shell session to allow RVM to load properly.
Install Ruby:
|
1 2 3 4 |
# I'm targeting 1.9.2; you can substitute with version of choice.
rvmsudo rvm install 1.9.2
# And, set 1.9.2 as system default
rvmsudo rvm use 1.9.2 --default |
Rails, and thin
Install Rails:
And, thin:
Install the thin daemon:
Because RoR and gang were installed via RVM, we need to make certain that thin (daemon) loads through the proper environment. This can be accomplish by creating a RVM wrapper for thin.
|
1 2 3 |
# Again, targeting 1.9.2p290 environment.
# Substitute as necessary.
rvmsudo rvm wrapper 1.9.2@/usr/local/rvm/gems/ruby-1.9.2-p290 daemon192 thin |
This will create the following script /usr/local/bin/daemon192_thin. Edit /etc/init.d/thin, and change the following line from:
…to:
thin daemon Configuration
For the purposes of this section, it’s assumed that target RoR application is in the following directory: /var/www/myapp.
Create a thin configuration file (Note: Remember to update path for your application):
This will generate a thin configuration file that will spawn (4) thin processes (cluster).
To start, and stop the thin damon:
Nginx
Simple nginx configuration to proxy thin cluster.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
upstream thin_cluster {
server 127.0.0.1:3000;
server 127.0.0.1:3001;
server 127.0.0.1:3002;
server 127.0.0.1:3003;
}
server {
listen 80;
server_name myapp.domain;
access_log /var/www/myapp/log/access.log;
error_log /var/www/myapp/log/error.log;
root /var/www/celox.me/public/;
index index.html;
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 off;
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://thin_cluster;
break;
}
}
} |
Johanns
What I'm Doing...
- Having to pay for Internet access at a "4/5-star" hotel is equivalent to having a coin operated TV in the room. 1 week ago
- #FirstWorldProblems Forgot batteries for active-noise canceling headphones before boarding 3-hour flight. Tech appreciation level-up! 1 week ago
- @NateReis I appreciate it, and will do. in reply to NateReis 2012-01-13
- @NateReis An internal "do NOT call list" would be great. Your sales associates claim there isn't one. 20+ calls in week is just annoying! 2012-01-13
- More updates...
Categories






