如何使用Passenger在Apache下设置Sinatra应用程序?

kch*_*kch 26 ruby apache rack passenger sinatra

假设我有最简单的单文件Sinatra应用程序.他们主页上的你好世界会做.我想在Apache下使用Phusion Passenger,AKA mod_rails运行它.

  • 我需要什么目录结构?
  • 我有什么要放在vhost conf文件上?
  • 我知道我需要一个机架文件.它包含了什么?为什么?

kch*_*kch 71

基本目录结构:

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
Run Code Online (Sandbox Code Playgroud)

虚拟主机文件:

<VirtualHost *:80>
  ServerName    app.example.com
  DocumentRoot  /path/to/app/public
  <Directory    /path/to/app/public>
    Order       allow,deny
    Allow       from all
  </Directory>
</VirtualHost>
Run Code Online (Sandbox Code Playgroud)

config.ru

# encoding: UTF-8
require './hello-app'
run Sinatra::Application
Run Code Online (Sandbox Code Playgroud)

hello-app.rb(示例应用程序):

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

get '/hi' do
  "Hello World!"
end
Run Code Online (Sandbox Code Playgroud)

restart.txt 是空的.


温和有用的链接: