How do I set up a Sinatra app under Apache with Passenger?

情到浓时终转凉″ 提交于 2019-12-18 09:59:34

问题


Let's say I have the simplest single-file Sinatra app. The hello world on their homepage will do. I want to run it under Apache with Phusion Passenger, AKA mod_rails.

  • What directory structure do I need?
  • What do I have to put in the vhost conf file?
  • I understand I need a rackup file. What goes in it and why?

回答1:


Basic directory structure:

app
|-- config.ru         # <- rackup file
|-- hello-app.rb      # <- your application
|-- public/           # <- static public files (passenger needs this)
`-- tmp/              
    `-- restart.txt   # <- touch this file to restart app

Virtual host file:

<VirtualHost *:80>
  ServerName    app.example.com
  DocumentRoot  /path/to/app/public
  <Directory    /path/to/app/public>
    Order       allow,deny
    Allow       from all
  </Directory>
</VirtualHost>

config.ru

# encoding: UTF-8
require './hello-app'
run Sinatra::Application

hello-app.rb (sample application):

#!/usr/bin/env ruby
# encoding: UTF-8
require 'rubygems' # for ruby 1.8
require 'sinatra'

get '/hi' do
  "Hello World!"
end

restart.txt is empty.


Mildly useful links:

  • Heroku rack documentation
  • Phusion Passenger documentation



回答2:


Example vhost file for rack app with passenger:

<VirtualHost *:80>
 ServerName   server.local
 ServerAlias  *.server.local
 DocumentRoot /dir/public
 RackEnv      development
 <Directory /dir/public>
 Order allow,deny
  Allow from all
 </Directory>
</VirtualHost>

Example Config.ru:

require File.expand_path('../boot.rb', __FILE__)
use Rack::Middleware
run Rack::Cascade.new([array])


来源:https://stackoverflow.com/questions/3371208/how-do-i-set-up-a-sinatra-app-under-apache-with-passenger

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!