Passenger + Nginx 部署Rails

1、Passenger简介

https://github.com/phusion/passenger

A fast and robust web server and application server for Ruby, Python and Node.js 

https://www.phusionpassenger.com/

https://www.phusionpassenger.com/library/dev/ruby/

https://www.phusionpassenger.com/library/dev/ruby/rails_integration.html

2、Nginx和Apache

最核心的区别在于apache是同步多进程模型,一个连接对应一个进程;nginx是异步的,多个连接(万级别)可以对应一个进程

3、Passenger + Apache部署Rails

http://blog.csdn.net/dazhi_100/article/details/17030045
https://segmentfault.com/a/1190000002621640

安装Apache

sudo apt-get install apache2
完成之后,访问:http://192.168.0.120/



安装Passenger

sudo gem install passenger
sudo passenger-install-apache2-module

安装过程中出现

Installation instructions for required software


 * To install Curl development headers with SSL support:
   Please run apt-get install libcurl4-openssl-dev or libcurl4-gnutls-dev, whichever you prefer.


 * To install Apache 2 development headers:
   Please install it with apt-get install apache2-dev


 * To install Apache Portable Runtime (APR) development headers:
   Please install it with apt-get install libapr1-dev


 * To install Apache Portable Runtime Utility (APU) development headers:
   Please install it with apt-get install libaprutil1-dev


If the aforementioned instructions didn't solve your problem, then please take
a look at our documentation for troubleshooting tips:


  https://www.phusionpassenger.com/library/install/apache/
  https://www.phusionpassenger.com/library/admin/apache/troubleshooting/

按照提示,安装必要的库,重试sudo passenger-install-apache2-module

若成功,可以看到输出文字中有这样的一段话

--------------------------------------------
Almost there!


Please edit your Apache configuration file, and add these lines:


   LoadModule passenger_module /var/lib/gems/2.2.0/gems/passenger-5.1.2/buildout/apache2/mod_passenger.so
   <IfModule mod_passenger.c>
     PassengerRoot /var/lib/gems/2.2.0/gems/passenger-5.1.2
     PassengerDefaultRuby /usr/bin/ruby2.2
   </IfModule>


After you restart Apache, you are ready to deploy any number of web
applications on Apache, with a minimum amount of configuration!


Press ENTER when you are done editing.




--------------------------------------------


修改Apache服务器配置

编辑/etc/apache2/apache2.conf

修改
<Directory />
Options FollowSymLinks
AllowOverride None
#Require all denied
Require all granted

</Directory>
增加
LoadModule passenger_module /var/lib/gems/2.2.0/gems/passenger-5.1.2/buildout/apache2/mod_passenger.so
<IfModule mod_passenger.c>
    PassengerRoot /var/lib/gems/2.2.0/gems/passenger-5.1.2
    PassengerDefaultRuby /usr/bin/ruby2.2
</IfModule>

编辑/etc/apache2/ports.conf

增加
Listen 8111

添加应用配置文件

在/etc/apache2/sites-available下增加配置文件rails-test.conf如下(实际上就是参照同级目录下000-default.conf改的):
<VirtualHost *:8111>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com


ServerAdmin webmaster@localhost
DocumentRoot /home/thinking/Documents/Aptana_Studio_3_Workspace/Tmp/MiNitPayDemo/public
RailsEnv development  
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn


ErrorLog /home/thinking/Documents/Aptana_Studio_3_Workspace/Tmp/MiNitPayDemo/error.log
CustomLog /home/thinking/Documents/Aptana_Studio_3_Workspace/Tmp/MiNitPayDemo/access.log combined


# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
</VirtualHost>


# vim: syntax=apache ts=4 sw=4 sts=4 sr noet


建立软连接
sudo ln -s /etc/apache2/sites-available/rails-test.conf /etc/apache2/sites-enabled/rails-test.conf

重启Apache

sudo /etc/init.d/apache2 stop
sudo /etc/init.d/apache2 start
访问:http://192.168.0.120:8111/


4、Passenger + Nginx 部署Rails



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值