Debian Rails3 Apache2 Passenger 部署

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>


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Debian 12是一个Linux操作系统的版本,而Apache2是一个开源的Web服务器软件。要在Debian 12上安装Apache2,您可以执行以下步骤: 1. 更新软件包列表: 使用命令 "apt-get update" 更新软件包列表. 2. 安装Apache2: 使用命令 "apt install -y apache2" 安装Apache2. 3. 启动Apache2服务: 使用命令 "systemctl start apache2" 启动Apache2服务. 另外,如果您想修改Apache2的配置文件,可以按照以下步骤进行操作: 1. 备份默认模板: 使用命令 "cp sites-available/default-ssl.conf sites-available/default-ssl.conf.bak" 备份默认的SSL配置模板. 2. 编辑配置文件: 使用命令 "nano sites-available/default-ssl.conf" 编辑默认的SSL配置文件。您可以修改DocumentRoot字段来指定网站的路径,同时也可以配置SSL证书的文件路径. 3. 保存并退出配置文件: 您可以使用适当的快捷键保存并退出配置文件. 4. (可选)创建其他配置文件: 如果您需要创建其他的网站配置文件,可以使用类似的步骤进行操作。记得将新的配置文件链接到/etc/apache2/sites-enabled目录下,以使其生效. 请注意,以上步骤仅适用于Debian 12中安装和配置Apache2的基本操作。具体的操作可能因不同的需求而有所不同。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [【linux】debian安装apache2并创建虚拟站点](https://blog.csdn.net/qq_43017750/article/details/103506980)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] - *2* [Debian配置apache2以及CA](https://blog.csdn.net/xs2126764969/article/details/124010585)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值