如何使用 Apache 2 和 Passenger 部署基于机架的 Ruby 应用程序?
How to deploy a Rack-based Ruby application with Apache 2 and Passenger?
我写了一个非常简单的 "hello world" ruby 脚本,我想在 apache2 (2.4) 下 运行 和 Ubuntu 14.04 上的乘客。这不是 rails 应用程序,我不想使用 rails 框架,这只是一个单页应用程序。
到目前为止,我所能得到的只是一个目录列表。这是我的文件。
uptime.rb
class Uptime
def call(env)
[200, {"Content-Type" => "text/plain"}, ["Hello world!"]]
end
end
宝石文件
source 'https://rubygems.org'
gem 'rack', '~>1.5.1'
config.ru
require './uptime'
run Uptime.new
/etc/apache2/mods-available/passenger.load
LoadModule passenger_module /usr/lib/apache2/modules/mod_passenger.so
/etc/apache2/mods-available/passenger.conf
<IfModule mod_passenger.c>
PassengerRoot /usr/lib/ruby/vendor_ruby/phusion_passenger/locations.ini
PassengerDefaultRuby /home/mark/.rbenv/shims/ruby
</IfModule>
/etc/apache2/sites-available/000-default.conf
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
PassengerRuby /home/mark/.rbenv/versions/2.3.1/bin/ruby
<Directory /var/www/html>
PassengerEnabled on
Allow from all
Options -MultiViews
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
乘客希望您的应用程序有一个 public
和一个 tmp
目录:
public
目录必须是您的 DocumentRoot
。如果 Passenger 被禁用/不工作,它将由 Apache 提供服务,因此没有人可以看到您的应用程序的源代码。
tmp
目录用于Passenger的restart.txt
。
您的目录树应该如下所示:
/var/www/html/
├── config.ru
├── uptime.rb
├── Gemfile
├── public/
└── tmp/
在您的配置中:
<VirtualHost *:80>
DocumentRoot /var/www/html/public
# ...
<Directory /var/www/html/public>
# ...
</Directory>
# ...
</VirtualHost>
我写了一个非常简单的 "hello world" ruby 脚本,我想在 apache2 (2.4) 下 运行 和 Ubuntu 14.04 上的乘客。这不是 rails 应用程序,我不想使用 rails 框架,这只是一个单页应用程序。
到目前为止,我所能得到的只是一个目录列表。这是我的文件。
uptime.rb
class Uptime
def call(env)
[200, {"Content-Type" => "text/plain"}, ["Hello world!"]]
end
end
宝石文件
source 'https://rubygems.org'
gem 'rack', '~>1.5.1'
config.ru
require './uptime'
run Uptime.new
/etc/apache2/mods-available/passenger.load
LoadModule passenger_module /usr/lib/apache2/modules/mod_passenger.so
/etc/apache2/mods-available/passenger.conf
<IfModule mod_passenger.c>
PassengerRoot /usr/lib/ruby/vendor_ruby/phusion_passenger/locations.ini
PassengerDefaultRuby /home/mark/.rbenv/shims/ruby
</IfModule>
/etc/apache2/sites-available/000-default.conf
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
PassengerRuby /home/mark/.rbenv/versions/2.3.1/bin/ruby
<Directory /var/www/html>
PassengerEnabled on
Allow from all
Options -MultiViews
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
乘客希望您的应用程序有一个 public
和一个 tmp
目录:
public
目录必须是您的DocumentRoot
。如果 Passenger 被禁用/不工作,它将由 Apache 提供服务,因此没有人可以看到您的应用程序的源代码。tmp
目录用于Passenger的restart.txt
。
您的目录树应该如下所示:
/var/www/html/
├── config.ru
├── uptime.rb
├── Gemfile
├── public/
└── tmp/
在您的配置中:
<VirtualHost *:80>
DocumentRoot /var/www/html/public
# ...
<Directory /var/www/html/public>
# ...
</Directory>
# ...
</VirtualHost>