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
    评论
Phusion Passenger是一种基于Nginx或Apache的应用服务器,它可以帮助我们快速、稳定地部署Rails应用。下面以Redmine为例,介绍在CentOS下如何使用Phusion Passenger方式部署Rails应用。 1. 安装必要的软件 首先需要安装Ruby、RailsNginxPassenger等软件,可以使用以下命令: ``` sudo yum install epel-release sudo yum install ruby ruby-devel rubygems gcc gcc-c++ make sqlite-devel sudo gem install rails sudo gem install passenger ``` 2. 安装NginxPassenger 使用以下命令安装NginxPassenger: ``` sudo yum install nginx sudo passenger-install-nginx-module ``` 在安装过程中,需要选择“1. Yes: download, compile and install Nginx for me”选项,让Passenger自动编译和安装Nginx。 3. 配置NginxPassenger 默认情况下,Passenger会自动添加Nginx的配置文件并启动Nginx服务,但是我们需要手动修改Nginx配置文件。 找到Nginx的配置文件,一般是/etc/nginx/nginx.conf,添加以下内容: ``` http { # ... server { listen 80; server_name yourserver.com; root /path/to/your/redmine/public; passenger_enabled on; passenger_ruby /usr/bin/ruby; passenger_app_env production; } } ``` 其中,yourserver.com是你的服务器域名或IP地址,/path/to/your/redmine是你的Redmine应用所在路径。 4. 启动Nginx服务 启动Nginx服务: ``` sudo systemctl start nginx ``` 5. 配置数据库 修改/config/database.yml文件,配置Redmine连接数据库的相关信息。 6. 初始化Redmine 在Redmine目录下运行以下命令初始化数据库: ``` RAILS_ENV=production bundle exec rake db:create RAILS_ENV=production bundle exec rake db:migrate RAILS_ENV=production bundle exec rake redmine:load_default_data ``` 7. 启动Redmine 在Redmine目录下运行以下命令启动Redmine: ``` RAILS_ENV=production bundle exec rails server -e production ``` 现在你就可以在浏览器中输入yourserver.com访问Redmine了。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值