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.

[cc lang="bash"]
# Existing homedir
/home/my_web/
# Current webroot
/home/my_web/htdocs
[/cc]

Creating folders and files for Sinatra

The first thing you want to do is to create folders and files for Sinatra.

[cc lang=bash]
mkdir /home/my_web/sinatra
[/cc]

[cc lang=bash]
cd /home/my_web/sinatra
mkdir tmp
mkdir logs
mkdir public
touch app.rb
touch config.ru
[/cc]

Create symlink

Create a symbolic link from our current webroot to the new Sinatra app so that apache/passenger can find it.

[cc lang="bash"]
ln -s /home/my_web/sinatra/public /home/my_web/htdocs/app
[/cc]

Creating the application

We also need a Sinatra application for this to work so lets fill those files.

File: config.ru

[cc lang="ruby"]
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
[/cc]

File: app.rb

[cc lang="ruby"]
require ‘rubygems’
require ’sinatra’

before do
# Strip the last / from the path
request.env['PATH_INFO'].gsub!(/\/$/, ”)
end

get ” do
“Hello world”
end
[/cc]

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:
[cc lang="apache"]
RackBaseURI /app
[/cc]
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

[cc lang="apache"]

ServerName www.example.com
ServerAlias example.com
DocumentRoot /home/my_web/htdocs/
RackBaseURI /app


Order allow,deny
Allow from all
AllowOverride All


[/cc]

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!

Posted in Hosting, Programming, Sinatra at November 30th, 2009. No Comments
Tagged with , , , , , , . Written by: Mathias Stjernström

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…

Posted in Hosting, Operatingsystem at November 5th, 2008. 2 Comments
Tagged with , , , , . Written by: Mathias Stjernström

Today one of our server got in trouble with an ACE encoded IDN domain. The problem seemed to be rails in combination with nginx’s X-Sendfile feature. The result became that when accessing the site trough the IDN domain x-senfile did not send any files….

Our quick and dirty solution (until we have found the source/or solved the problem) became redirecting all traffic from the IDN domain to the domain without strange-swedish-characters.

With nginx this is as simple as in most webservers just put the following code before you original server configuration in nginx.conf.

[cc lang="html"]
server {
server_name xn--svenskdomn-y5a.se www.xn--svenskdomn-y5a.se;
rewrite ^(.*) http://www.svenskdoman.se$1 permanent;
}
[/cc]

And Bowang! All requests to www.svenskdomän.se will be redirected to www.svenskdoman.se.

Domain names have been changed to protect the innocent :-)

Cheers!

Posted in Hosting, Rails at May 21st, 2008. No Comments
Tagged with , , . Written by: Mathias Stjernström

pastbedti.me is using WP-Gravatar