Debian Rails3 Apache2 Passenger 部署

来源:互联网 发布:ios变音软件 编辑:程序博客网 时间:2024/05/18 04:00

1. 编译安装apache2


2. 安装passenger

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

根据提示安装缺少的依赖包(不同机器可能不同,看提示)

sudo apt-get install libcurl4-openssl-dev
sudo apt-get install apache2-mpm-prefork
sudo apt-get install apache2-prefork-dev
sudo apt-get install libapr1-dev
sudo apt-get install libaprutil1-dev


再次运行 sudo passenger-install-apache2-module

依赖都通过的话 就会开始编译一些文件了,最后会提示

把以下内容加到配置文件里去(可以用sudo apache2ctl -V | grep SERVER_CONFIG_FILE命令查看配置文件位置)

如:-D SERVER_CONFIG_FILE="apache2.conf"   在/etc/apache2目录下


apache2.conf中有这样一段

# Include all the user configurations:
Include httpd.conf


说明

apache2.conf 会自动加载同目录下的httpd.conf文件 所以把以下内容加到httpd.conf中即可


LoadModule passenger_module /usr/local/lib/ruby/gems/1.9.1/gems/passenger-3.0.9/ext/apache2/mod_passenger.so
PassengerRoot /usr/local/lib/ruby/gems/1.9.1/gems/passenger-3.0.9
PassengerRuby /usr/local/bin/ruby


3.配置发布在 apache2 配置文件中加入

   <VirtualHost *:80>
      ServerName www.yourhost.com
      DocumentRoot /somewhere/public    # <-- be sure to point to 'public'!
      <Directory /somewhere/public>
         AllowOverride all                 # <-- relax Apache security settings
         Options -MultiViews            # <-- MultiViews must be turned off
      </Directory>
   </VirtualHost>

本机测试的话,修改/etc/hosts文件,加入

127.0.0.1 www.yourhost.com

重启apache2服务 sudo apache2ctl restart 即可访问www.yourhost.com


4.重启应用而不重启apache 

在项目目录下

$ touch tmp/restart.txt


5. RailsEnv development

如果要在开发环境下使用passenger ,在配置文件中加入 RailsEnv development

每次请求过后,都会reload应用

If you set RailsEnv development in your Apache configuration,then Rails will automatically reload your application code after each request.


7.完整例子  添加的部分 httpd.conf

LoadModule passenger_module /usr/local/lib/ruby/gems/1.9.1/gems/passenger-3.0.9/ext/apache2/mod_passenger.so
PassengerRoot /usr/local/lib/ruby/gems/1.9.1/gems/passenger-3.0.9
PassengerRuby /usr/local/bin/ruby

<VirtualHost *:80>
   ServerName new.my.com
   DocumentRoot /home/rex/ror/projects/newapp/public
   RailsEnv development
  <Directory /home/rex/ror/projects/newapp/public>
    Allow from all
    Options -MultiViews
  </Directory>

</VirtualHost>


转自:http://blog.csdn.net/clskkk2222/article/details/6793810

原创粉丝点击