My Sinatra + Apache + Passenger setup did not just run
Deploying a simple Sinatra rack application under Apache and Phusion Passenger turned out not work out of the box for me.
I already had a virtual host so I decided to deploy with passengers sub URI (sub URI documentation).
To make this work you’ll need Apache installed with Phusion Passenger setup (Passenger installation)
This is what I started with
This is my folders for the already existing website.
1 2 3 4
| # Existing homedir
/home/my_web/
# Current webroot
/home/my_web/htdocs |
Creating folders and files for Sinatra
The first thing you want to do is to create folders and files for Sinatra.
1
| mkdir /home/my_web/sinatra |
1 2 3 4 5 6
| cd /home/my_web/sinatra
mkdir tmp
mkdir logs
mkdir public
touch app.rb
touch config.ru |
Create symlink
Create a symbolic link from our current webroot to the new Sinatra app so that apache/passenger can find it.
1
| ln -s /home/my_web/sinatra/public /home/my_web/htdocs/app |
Creating the application
We also need a Sinatra application for this to work so lets fill those files.
File: config.ru
1 2 3 4 5 6 7 8 9 10 11
| require 'app'
set :environment, ENV['RACK_ENV'].to_sym
set :app_file, 'app.rb'
disable :run
log = File.new("logs/sinatra.log", "a")
STDOUT.reopen(log)
STDERR.reopen(log)
run Sinatra::Application |
File: app.rb
1 2 3 4 5 6 7 8 9 10 11
| require 'rubygems'
require 'sinatra'
before do
# Strip the last / from the path
request.env['PATH_INFO'].gsub!(/\/$/, '')
end
get '' do
"Hello world"
end |
Apache configuration
Now we need to setup apache so that it can find our Sinatra app and load it.
The only thing you need to do is add the following line to your existing VirtualHost block:
This line will tell passenger to look into our existing webroot for a symlink thats named app and which points to our rack app. (RackBaseURI documentation)
Virtual host entry
1 2 3 4 5 6 7 8 9 10 11 12
| <VirtualHost *:80>
ServerName www.example.com
ServerAlias example.com
DocumentRoot /home/my_web/htdocs/
RackBaseURI /app
<Directory "/home/my_web/htdocs/">
Order allow,deny
Allow from all
AllowOverride All
</Directory>
</VirtualHost> |
The best part is that you are allowed to specify this option multiple times. So you can easily setup multiple apps under the same virtual host.
Cheers!
When helping a friend last night with couchdb a got stuck when trying to start it as an unprivileged user. The error messages you get from couchdb is far from easy to understand.
This is my way of solving it.
Read More…
Posted in
Databases,
Hosting at April 10th, 2009.
5 Comments
Tagged with
couchdb,
howto,
unprivileged. Written by:
stjernstrom
Today I had a really painful experience with rails InvalidAuthenticityToken. It turned out not to have anything to do with rails at all and there is where the painful part come in to play.
Read More…
Just before christmas I worked with one of our customers new server cluster or cloud if you may.
This cluster has production nodes and staging nodes and this post is about how to get capistrano to play nice with both production and the staging environment.
Read More…
Today I where about to analyze a PostgreSQL database with the wonderful pgFouine. On the machine syslog-ng where installed as logging daemon and I have never worked with PostgreSQL logging and syslog-ng. This post is about how to get them to work together.
Read More…
Today I got the chance to give Ruby Enterprise Edition a try. We are currently working with a really fun new environment and you do not get better opportunities to try new stuff as when you have a complete new environment thats not in production. So we gave REE a shoot. When compiling REE with got in trouble really fast and this post is about the quick fix to solve it and some of our early performance results.
Read More…
This is a little memory note for my self and hopefully it can help someone else how to reset MySQL root password.
It happens that we are asked to do some work on our customers dedicated servers and when that happens it’s not that uncommon that there is not a single person alive that has the root password for the MySQL server. When that happen it’s good to know how to reset it
This post is about how simple it’s to reset MySQL’s root password under FreeBSD.
Read More…
Posted in
Databases,
Hosting,
MySQL at November 24th, 2008.
6 Comments
Tagged with
freebsd,
MySQL,
passwords. Written by:
stjernstrom
Today I was playing with nginx’s flv module. The page I made where private enough to password protect so i thought it would be great opportunity to learn how to do this with nginx.
Read More…
Posted in
Hosting at November 8th, 2008.
2 Comments
Tagged with
apache,
nginx,
passwords. Written by:
stjernstrom
We recently got in trouble with two Gentoo machines that where running under VMware ESX & ESXi.
The hosts froze randomly (Even the console in vmware froze). Especially when putting a little load on the machines. After hours of testing we found that removing virtual CPU’s from the host solved the problem. More that one CPU got the machine to freeze after some time.
!! Unsatisfied solution !! So after a couple of more hours we found a working solution….
Read More…
This is how I did a quick fix for a client of ours that are running a Ruby On Rails app behind an nginx/mongrel setup.
The mission where to move their wordpress weblog to the same server as the website.
The easiest way had been to add another IP and install apache behind it. They did not like this solution because they thought they where about to loose google page-rank if the blog and the website where on different ip’s. ok, Fair enough.
The simple solution became to install apache and just proxy the request thought nginx.
Read More…
Posted in
Hosting at July 3rd, 2008.
2 Comments
Tagged with
apache,
nginx,
proxy,
wordpress. Written by:
stjernstrom