本文的目的是尽可能浅显的介绍Ruby + Passenger的使用。如果想深入了解Passenger,可参考后续相关章节。

本人通过有无Passenger启动Rubyf服务来入门Passenger

Ruby + Passenger 实验

无Passenger启动服务

*
准备Ruby程序
# 此项目是本人在github上提交的Ruby demo程序 git clone
https://github.com/testcara/ROR_Blog.git
 

*
安装Gem包
# check the Gemfile and install the Gems # enter the dir cd ROR_Blog # confirm
whether it is has the 'passenger' cat Gemfile | grep -r -i 'passenger' #
install packages without production mode bundle install --without production
 

*
直接启动服务
# start the service rails s # then open the http://localhost:3000 to check the
main page of the application
 

*
验证进程
# check the ruby related process ps aux | grep ruby # we will see there is
only one ruby process ‘rails’
*
确认log
# check the log files under the 'log' dir ll log # then we can see there is no
passenger*.log
 

Passenger启动服务

*  编辑Gemfile添加Passenger # add passenger to Gemfile echo 'gem "passenger",
require: "phusion_passenger/rack_handler"' >> Gemfile
 

* 安装Gems, 包含Passenger # confirm the passenger existing in the 'passenger' cat
Gemfile | grep 'passenger' # install Gemfiles including the 'passenger' bundle
install --without production
 

* 启动passenger # kill the 'rails s' to free the 3000 port # start passenger
service passenger start
 

* 验证进程 # check the ruby related process ps aux | grep ruby # then we would
see one ruby process 'passenger'
* 确认log # check the log files under the 'log' dir ll log # then we can see
there is one passenger*.log
 

以上可见,

通过Passenger启动Ruby程序是非常简单的。Ruby on Rails框架提供了内嵌的服务器工具。这些服务器工具可以和rails
server命令进行交互。rails server不是一个应用服务器,
仅仅是启动应用和应用服务器的wrapper。如果Gemfile中指定了Passenger,则rails
server会启动Passenger而不是默认服务器,如果没有Passenger,则会启动默认应用服务区。

通常在生产环境中,我们不会直接使用rails s起启动服务,而使用Passenger等应用服务器的原因。

友情链接
KaDraw流程图
API参考文档
OK工具箱
云服务器优惠
阿里云优惠券
腾讯云优惠券
华为云优惠券
站点信息
问题反馈
邮箱:[email protected]
QQ群:637538335
关注微信