简体   繁体   English

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

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

Let's say I have the simplest single-file Sinatra app. 假设我有最简单的单文件Sinatra应用程序。 The hello world on their homepage will do. 他们主页上的你好世界会做。 I want to run it under Apache with Phusion Passenger, AKA mod_rails. 我想在Apache下用Phusion Passenger,AKA mod_rails运行它。

  • What directory structure do I need? 我需要什么目录结构?
  • What do I have to put in the vhost conf file? 我需要在vhost conf文件中添加什么内容?
  • I understand I need a rackup file. 我知道我需要一个机架文件。 What goes in it and why? 它包含了什么?为什么?

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 config.ru

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

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

#!/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. restart.txt为空。


Mildly useful links: 温和有用的链接:

Example vhost file for rack app with passenger: 带乘客的机架应用程序示例vhost文件:

<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: 示例Config.ru:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM