Sinatra on Nginx on Ubuntu on Passenger

Just wanted to share our setup, as reminder and help for others 😉

(do not forget to create a tmp and public folder inside your projects folder)

#/opt/nginx/conf/nginx.conf
server {
  listen 80;
  server_name xxx.yyy.com;

  access_log /var/log/xxx_access.log  main;
  error_log /var/log/xxx_error.log debug;
  root /srv/xxx/public;   # <--- be sure to point to 'public'!
  passenger_use_global_queue on;
}

#/etc/hosts
127.0.0.1       xxx.yyy.com

#config.ru
require 'app'
disable :run
set :root, Pathname(__FILE__).dirname
run Sinatra::Application

#app.rb
require 'rubygems'
require 'sinatra'

get "/" do
  "Hello world from xxx"
end

Ubuntu Karmic Koala is here, time for a fresh install

Since my old Ubuntu lived a long live and saw numerous hacks, I chose to reinstall from scratch, here are the steps I took:

  1. install dotfiles
  2. Skype
  3. Multi-clipboard: sudo apt-get install glipper
  4. Application laucher: sudo apt-get install gnome-do + enable skype plugin
  5. Ruby enterprise
  6. Rubymine + Desktop icon+ Meta key for Rubymine
  7. Mysql: sudo apt-get install mysql-server mysql-client libmysql-ruby
  8. Apache:  sudo apt-get install apache2 apache2-mpm-prefork apache2-prefork-dev
  9. Passenger
  10. SSL for apache/passenger
  11. gem sources -a http://gems.github.com
  12. gems…
  13. Java: sudo apt-get install sun-java6-jre
  14. Git: sudo apt-get install git-core

No more hacks, everything works, very fast startup (~10s), faster graphics (for intel chips) 😀

My new desktop

My new desktop

SSL/HTTPS for Passenger in development on Ubuntu Jaunty

Making a certificate

sudo mkdir /etc/apache2/ssl
sudo /usr/sbin/make-ssl-cert /usr/share/ssl-cert/ssleay.cnf /etc/apache2/ssl/apache.pem
sudo a2dissite default-ssl
sudo a2enmod ssl
sudo /etc/init.d/apache2 restart

Configure passenger

<VirtualHost *:80>
 ServerAlias *.something.com
 RailsEnv development
 DocumentRoot /apps/something/public
</VirtualHost>
<VirtualHost *:443>
 SSLEngine on
 SSLCertificateFile /etc/apache2/ssl/apache.pem
 ServerAlias *.something.com
 RailsEnv development
 DocumentRoot /apps/something/public
</VirtualHost>

host

Automated SSH Login with Password and Additional Commands

The normal answer to most ssh related problems is: “use public/private keys”
but sometimes this does not work…

What i did regularly was this:

  • ssh to xxx@asdads.com
  • enter password
  • sudo su admin
  • cd /apps/hosts/some_project

Thats not very complicated, but its frustrating. What I do now is: “sshxx”, which executes this excpect script in ~/bin/sshxx

#!/usr/bin/expect
set pass [lindex $argv 0] #get first argument
spawn ssh xxx@asdads.com
expect "assword" #matches Password and password
send "$pass\r"
expect "xxx@" #wait for the prompt
send "sudo su admin\r"
send "cd /apps/hosts/some_project\r"
send "clear\r" #clean up the mess
interact

(For Ubuntu you need to “sudo apt get install expect” first)

Passenger for Local Development of Multiple Applications on Ubuntu

Starting with the Railscasts episode on passenger I tried to get passenger working for development, since it removes the burden of always starting an extra console for the server and reveals errors that happen in passenger and not in mongel alone.

Apache should use the same group/user you use, otherwise you may get an 302 not allowed error, this can be changed in /etc/apach2/apache2.conf (User / Group).

httpd.conf

#/ets/apacha2/httpd.conf
# /apps is the folder where your projects lie
# I name them all *.lc so i can easily distinguish them from a live application
# if you use subdomains add the *. before the servername (example 1)
<Directory "/apps">
  Order allow,deny
  Allow from all
</Directory>

<Directory "/apps">
  Options FollowSymLinks
  AllowOverride None
</Directory>

<VirtualHost *:80>
  ServerAlias *.dw.lc
  PassengerPoolIdleTime 1800
  RailsEnv development
  DocumentRoot /apps/someproject/public
</VirtualHost>

<VirtualHost *:80>
  ServerAlias rs.lc
  PassengerPoolIdleTime 1800
  RailsEnv development
  DocumentRoot /apps/anotherproject/public
</VirtualHost>

hosts file

#/ets/hosts
127.0.0.1       de.dw.lc en.dw.lc fr.dw.lc
127.0.0.1       rs.lc
127.0.0.1       localhost
...

restart apache

sudo /etc/init.d/apache2 restart

Hope it works for you 😉