Recipe for Ubuntu Intrepid (8.10) Server with Nginx and Passenger
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
README.mdown

README.mdown

Ubuntu Intrepid (8.10) with Nginx and Passenger

This recipe assumes you are logged in as the root user on a clean Ubuntu 8.10 server!

Use and abuse this at your own peril. I wrote this in a hurry :-)

Updating the server

####Update/Upgrade the server packages

apt-get update
apt-get upgrade

####Configure the timezone and update the time

dpkg-reconfigure tzdata
apt-get install ntp -y
ntpdate ntp.ubuntu.com

####Edit SSH daemon configuration

vi /etc/ssh/sshd_config

...
PermitRootLogin no
...
PasswordAuthentication no
...

Setting up a deployment user

####Add the deploy user. You should use this user in your Capistrano recipes.

adduser deploy

####Create the .ssh directory for the deploy user

su - -c "mkdir .ssh;chmod 700 .ssh" deploy

####Add a SSH public key to the deploy user. This is a public key from a person that needs to deploy applications. Add as many as you need.

su - -c "vi .ssh/authorized_keys" deploy
su - -c "chmod 600 .ssh/authorized_keys" deploy

####Create the apps directory for the deploy user. This is the root directory to use for deploying your applications.

su - -c "mkdir ~/apps" deploy
chmod 755 ~deploy/apps

###Optional If the deploy user will need to execute sudo using Capistrano or otherwise, do the following:

####Enable the sudo group

visudo

...
%sudo ALL=NOPASSWD: ALL
...

####Add the deploy user to the sudo group

usermod -G sudo -a deploy

Installing Git

####Install the git-core package

apt-get install git-core -y

Installing MySQL

####Install the mysql-server and libmysqlclient15-dev packages

apt-get install mysql-server libmysqlclient15-dev -y

Installing Ruby Enterprise Edition and Passenger

Note that this also installs Rails and a bunch of other gems...

####Download and install ruby

apt-get install build-essential zlib1g-dev libssl-dev libreadline5-dev -y
wget http://www.rubyenterpriseedition.com/ruby-enterprise-1.8.6-20090610.tar.gz
tar xvfz ruby-enterprise-1.8.6-20090610.tar.gz
rm ruby-enterprise-1.8.6-20090610.tar.gz
cd ruby-enterprise-1.8.6-20090610/
./installer
cd ..
rm -rf ruby-enterprise-1.8.6-20090610

####Create links to the new binaries in the system path. This avoids issues with sudo secure paths.

ln -s /opt/ruby-enterprise-1.8.6-20090610/bin/erb /usr/local/bin/erb
ln -s /opt/ruby-enterprise-1.8.6-20090610/bin/gem /usr/local/bin/gem
ln -s /opt/ruby-enterprise-1.8.6-20090610/bin/irb /usr/local/bin/irb
ln -s /opt/ruby-enterprise-1.8.6-20090610/bin/rails /usr/local/bin/rails
ln -s /opt/ruby-enterprise-1.8.6-20090610/bin/rake /usr/local/bin/rake
ln -s /opt/ruby-enterprise-1.8.6-20090610/bin/rdoc /usr/local/bin/rdoc
ln -s /opt/ruby-enterprise-1.8.6-20090610/bin/ri /usr/local/bin/ri
ln -s /opt/ruby-enterprise-1.8.6-20090610/bin/ruby /usr/local/bin/ruby

####Tell gem not to create documentation, ever.

vi /root/.gemrc

---
:sources:
- http://gems.rubyforge.org
- http://gems.github.com
gem: --no-ri --no-rdoc

####Copy the .gemrc file for the deploy user

cp /root/.gemrc ~deploy/.gemrc
chown deploy:deploy ~deploy/.gemrc

####Install the thor gem

gem install thor
ln -s /opt/ruby-enterprise-1.8.6-20090610/bin/thor /usr/local/bin/thor

Installing Nginx

What happens here is that Nginx gets installed several times. The end result is the Ubuntu distribution nginx and it's support files are used with the binary from the Passenger module installation. This approach has the advantage of using the site management directories as well as the init.d support.

####Install the nginx and the libpcre3-dev package

apt-get install nginx libpcre3-dev -y

####Test the web server and remove the default site

/etc/init.d/nginx start
curl http://localhost
rm /etc/nginx/sites-enabled/default
/etc/init.d/nginx stop

Installing the Passenger Nginx module

####Start the Passenger Nginx module installation

/opt/ruby-enterprise-1.8.6-20090610/bin/passenger-install-nginx-module

####Select option 1, hit enter at the prompts and wait for it to finish

...
Phusion Passenger is a trademark of Hongli Lai & Ninh Bui.

####Start the Passenger Nginx module installation (again)

/opt/ruby-enterprise-1.8.6-20090610/bin/passenger-install-nginx-module

####Select option 2 to customize the Nginx install. When the installer asks, "Where is your Nginx source code located?", enter:

/tmp/nginx-0.6.36

####On, extra arguments to pass to configure script add:

--with-http_ssl_module

####Wait for the Passenger Nginx module installation to finish

...
Phusion Passenger is a trademark of Hongli Lai & Ninh Bui.

####Edit the Nginx configuration from the apt-get nginx install

vi /etc/nginx/nginx.conf
    
http {
  ...
  passenger_root /opt/ruby-enterprise-1.8.6-20090610/lib/ruby/gems/1.8/gems/passenger-2.2.2;
  passenger_ruby /opt/ruby-enterprise-1.8.6-20090610/bin/ruby;
  ...
}

####Edit the Nginx init.d script from the apt-get nginx install

vi /etc/init.d/nginx

...
DAEMON=/opt/nginx/sbin/nginx
...

####Link the Passenger Nginx configuration to the apt-get nginx configuration

rm /opt/nginx/conf/nginx.conf
ln -s /etc/nginx/nginx.conf /opt/nginx/conf/nginx.conf

####Start Nginx

/etc/init.d/nginx start

Deploying a Rack application

For a whole bunch of info on using Rack with Passenger, take a look at the documentation.

####Create the new virtual configuration

vi /etc/nginx/sites-available/www.yourhost.com

# your application configuration
server {
  listen 80;
  server_name www.yourhost.com;
  root /home/deploy/apps/yourapp/public;   # <--- be sure to point to 'public'!
  passenger_enabled on;
}

####Enable the site

ln -s /etc/nginx/sites-available/www.yourhost.com /etc/nginx/sites-enabled/001-www.yourhost.com

####Reload the Nginx configuration

/etc/init.d/nginx reload

Installing SSL for Nginx

If you need SSL enabled for an application, follow this easy article at Slicehost. It walks through creating a self-signed certificate as well as setting Nginx up to use it.

More Resources

Phusion Passenger users guide, Nginx version