Sinatra + Passenger + Apache

220 views
Skip to first unread message

joe

unread,
Nov 30, 2009, 1:01:17 PM11/30/09
to sinatrarb
Trying to setup a Sinatra app to work with Passenger + Apache and I'm
having some issues.

I've searched around and found several solutions which all look
similar, but none of them seem to be working..

My app structure is this:
app/
- lib/
- public/
- tmp/
-- restart.txt
- config.ru
- app.rb

This is all that's in my app.rb file:
------------------------------------------------------------------------------------------
require 'rubygems'
require 'sinatra'

get '/' do
"Hello there"
end
------------------------------------------------------------------------------------------

This is my config.ru file (straight from the passenger docs):
------------------------------------------------------------------------------------------
require 'rubygems'
require 'sinatra'

root_dir = File.dirname(__FILE__)

set :environment, ENV['RACK_ENV'].to_sym
set :root, root_dir
set :app_file, File.join(root_dir, 'app.rb')
disable :run

run Sinatra::Application
------------------------------------------------------------------------------------------

My httpd.conf contains:
------------------------------------------------------------------------------------------
LoadModule passenger_module /usr/lib/ruby/gems/1.8/gems/
passenger-2.2.7/ext/apache2/mod_passenger.so
PassengerRoot /usr/lib/ruby/gems/1.8/gems/passenger-2.2.7
PassengerRuby /usr/bin/ruby1.8

# Sinatra host
<VirtualHost *:80>
ServerName localhost:8080
DocumentRoot /var/www/app/public
RackBaseURI /app
</VirtualHost>
------------------------------------------------------------------------------------------

Note: /var/www/app is a sym link of /home/user/code/app. Don't know
if it matters or not, but that's how I'd like it setup.

So what am I missing here?

Damian Janowski

unread,
Nov 30, 2009, 1:04:22 PM11/30/09
to sina...@googlegroups.com
On Mon, Nov 30, 2009 at 3:01 PM, joe <ehas...@gmail.com> wrote:
> Trying to setup a Sinatra app to work with Passenger + Apache and I'm
> having some issues.
>
> [...]
>
> Note:  /var/www/app is a sym link of /home/user/code/app.  Don't know
> if it matters or not, but that's how I'd like it setup.
>
> So what am I missing here?

Unicorn http://unicorn.bogomips.org :-)

Maybe you need to enable FollowSymLinks or something like that in Apache?

joe

unread,
Nov 30, 2009, 1:16:09 PM11/30/09
to sinatrarb
On Nov 30, 1:04 pm, Damian Janowski <damian.janow...@gmail.com> wrote:
> On Mon, Nov 30, 2009 at 3:01 PM, joe <ehass...@gmail.com> wrote:
>
> Maybe you need to enable FollowSymLinks or something like that in Apache?

Adding something like:
<VirtualHost *:80>
ServerName localhost:8080
DocumentRoot /var/www/app/public
RackBaseURI /app
<Directory /var/www/app/public>
Options Indexes FollowSymLinks
</Directory>
</VirtualHost>

Doesn't seem to do it either; I just keep getting 404 errors.

MilesTogoe

unread,
Nov 30, 2009, 1:21:02 PM11/30/09
to sina...@googlegroups.com
not entirely sure but we run Sinatra just fine with Passenger using Ruby
1.9.1 - for this you need to change File.dirname(..) to
Pathname(...).dirname and File.join(..) to root_dir.join(..) You might
want to check your set :environment - we just use simple :production or
:development


joe

unread,
Nov 30, 2009, 1:33:33 PM11/30/09
to sinatrarb
I'm currently using ruby 1.8.7.

I also just changed my config.ru to hardly contain anything:
------------------------------------------------------------------------------------------
require 'rubygems'
require 'sinatra'

set :environment, :development
require 'app'
run Sinatra::Application
------------------------------------------------------------------------------------------

I also changed my vhost block to be:
------------------------------------------------------------------------------------------
<VirtualHost *:80>
ServerName localhost:8080
DocumentRoot /var/www/app/public
ErrorLog /var/www/app/log/sinatra_error_log
CustomLog /var/www/app/log/sinatra_access_log common
<Directory /var/www/app/public>
Options FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
------------------------------------------------------------------------------------------

Only new thing that happened was the error log files were generated in
the new log/ dir I just created. Still just getting 404 errors.

joe

unread,
Nov 30, 2009, 2:18:24 PM11/30/09
to sinatrarb
The apache error.log file has been spitting out a lot of this:

[Mon Nov 30 13:53:16 2009] [error] [client 10.0.2.2] Attempt to serve
directory: /var/www/app/
[Mon Nov 30 14:03:59 2009] [error] [client 10.0.2.2] Attempt to serve
directory: /var/www/app/
[Mon Nov 30 14:09:34 2009] [error] [client 10.0.2.2] Attempt to serve
directory: /var/www/app/

Should it be attempting to go there or should it be trying to visit /
var/www/app/public?

Christoph Jasinski

unread,
Nov 30, 2009, 2:30:25 PM11/30/09
to sina...@googlegroups.com
Hi,

try to change your config.ru to this

****************config.ru*****************
# require 'rubygems'
# require 'sinatra'
require 'app.rb'
.
.
.
.

**********************

What is your sinatra version?


Cheers
Chris

joe

unread,
Nov 30, 2009, 2:50:32 PM11/30/09
to sinatrarb
Well, I think I got it to work. I think I actually just messed up the
symlink. First I got things to work with just going to localhost:8080
and finally got everything to work with a URI (localhost:8080/app).

I indeed need to have require 'app.rb' in my config.ru file or I would
just end up at a blank page.

My config.ru is now looking like this:
------------------------------------------------------------
require 'rubygems'
require 'sinatra'
require 'app.rb'

root_dir = File.dirname(__FILE__)

set :environment, :development
set :root, root_dir
set :app_file, File.join(root_dir, 'app.rb')
disable :run

run Sinatra::Application
------------------------------------------------------------

My vhost block is now:
------------------------------------------------------------
<VirtualHost *:80>
ServerName localhost:8080
DocumentRoot /var/www
ErrorLog /home/user/code/app/log/sinatra_error_log
CustomLog /home/user/code/app/log/sinatra_access_log common
<Directory /var/www>
RackBaseURI /app
Options FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
------------------------------------------------------------

Things seem to be working now. Phew. Thanks everyone for your input.

Mathias Stjernström

unread,
Nov 30, 2009, 2:48:50 PM11/30/09
to sina...@googlegroups.com
Hi Joe!

Try this config.ru:

require 'rubygems'
require 'sinatra'


set :environment, ENV['RACK_ENV'].to_sym

set :app_file, 'app.rb'
disable :run

require 'app'

run Sinatra::Application

> My httpd.conf contains:
> ------------------------------------------------------------------------------------------


>
> # Sinatra host
> <VirtualHost *:80>
> ServerName localhost:8080
> DocumentRoot /var/www/app/public
> RackBaseURI /app
> </VirtualHost>
> ------------------------------------------------------------------------------------------
>

Try changing your DocumentRoot to /var/www

In this case passenger tries to find a symlink inside /var/www that is
named app and points to your public folder.

> Note: /var/www/app is a sym link of /home/user/code/app. Don't know
> if it matters or not, but that's how I'd like it setup.

Change your symlink to point to the public folder

ln -s /home/user/code/app/public /var/www/app


Note that when using sinatra modular design or when using RackBaseURI
you also get a root path which is empty.

get '' do
"Hello roootlessss"
end

This can be fixed with a little before filter:

before do
request.env['PATH_INFO'] = '/' if request.env['PATH_INFO'] == ''
end

or you can do this:

before do
request.env['PATH_INFO'].gsub!(/\/$/, '')
end

This removes trailing / from all requests and you can use only a "get
'' do" for root.


Cheers

Mathias Stjernstrom
-------------------------------------------
http://www.pastbedti.me/


PGP.sig

joe

unread,
Nov 30, 2009, 3:12:39 PM11/30/09
to sinatrarb


On Nov 30, 2:48 pm, Mathias Stjernström <math...@globalinn.com> wrote:
>
> Note that when using sinatra modular design or when using RackBaseURI  
> you also get a root path which is empty.
>
> get '' do
>    "Hello roootlessss"
> end
>
> This can be fixed with a little before filter:
>
> before do
>    request.env['PATH_INFO'] = '/' if request.env['PATH_INFO'] == ''
> end
>
> or you can do this:
>
> before do
>    request.env['PATH_INFO'].gsub!(/\/$/, '')
> end
>
> This removes trailing / from all requests and you can use only a "get  
> '' do" for root.

How do you even access the rootless handler? I just get thrown to '/'
and I'm using a URI.

I also have..
before do
request.env['PATH_INFO'] = '/' if request.env['PATH_INFO'] == ''
end

in my app.rb file.

Mathias Stjernström

unread,
Nov 30, 2009, 3:38:46 PM11/30/09
to sina...@googlegroups.com
> How do you even access the rootless handler? I just get thrown to '/'
> and I'm using a URI.
>
> I also have..
> before do
> request.env['PATH_INFO'] = '/' if request.env['PATH_INFO'] == ''
> end
>
> in my app.rb file.

If you have that before block you'll rewrite "" to "/".

PGP.sig
Reply all
Reply to author
Forward
0 new messages