Ruby-on-rails Apache2 的 Rails 乘客问题

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6316875/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 01:22:26  来源:igfitidea点击:

Rails Passenger problem with Apache2

ruby-on-railsapache2passengerubuntu-10.10mod-rails

提问by Andre Schweighofer

I'm trying to setup a ruby on rails server on ubuntu10.10 with apache2 and mod_rails (Phusion Passenger).

我正在尝试使用 apache2 和 mod_rails(Phusion 乘客)在 ubuntu10.10 上的 rails 服务器上设置一个 ruby​​。

I already installed ruby 1.9.2-p0 and rails 3.0.8 and installed Passenger with the passenger-install-apache2-module and the passenger gem (v3.0.7).

我已经安装了 ruby​​ 1.9.2-p0 和 rails 3.0.8,并安装了带有passenger-install-apache2-module 和passenger gem (v3.0.7) 的Passenger。

It then tells me to add 3 lines to my Apache config file. So I added these lines to '/etc/apache2/apache2.conf':

然后它告诉我在我的 Apache 配置文件中添加 3 行。所以我将这些行添加到“/etc/apache2/apache2.conf”中:

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

And I edited my '/etc/apache2/httpd.conf' and added:

我编辑了我的“/etc/apache2/httpd.conf”并添加了:

NameVirtualHost *:80

<VirtualHost *:80>
ServerName 192.168.0.2
DocumentRoot /var/www/webop/public

<Directory /var/www/webop/public>
Allow from all
Options -MultiViews
</Directory>
</VirtualHost>

I also found out that the file mod_passenger.so in /usr/local/lib/ruby/gems/1.9.1/gems/passenger-3.0.7/ext/apache2/ actually does not exist, its name is mod_passenger.c. But I don't get any errors from that.

我还发现/usr/local/lib/ruby/gems/1.9.1/gems/passenger-3.0.7/ext/apache2/中的mod_passenger.so文件实际上并不存在,它的名字是mod_passenger.c。但我没有从中得到任何错误。

The server should only be accessible through a LAN. When I access the server I see all the files and directories in the public folder of my app but the app itself does not get started.

服务器应该只能通过 LAN 访问。当我访问服务器时,我看到我的应用程序的公共文件夹中的所有文件和目录,但应用程序本身没有启动。

When I restart apache it tells me that mod_rails is already loaded so I guess that passenger is running but I can't figure out why it doesn't start my app!

当我重新启动 apache 时,它​​告诉我 mod_rails 已经加载,所以我猜乘客正在运行,但我不知道为什么它不启动我的应用程序!

Thanks in advance!

提前致谢!

采纳答案by Andre Schweighofer

I finally figured out what the problem was: I messed up my ruby installation.

我终于弄清楚问题出在哪里:我搞砸了我的 ruby​​ 安装。

In /usr/local/ I had ruby1.9.2-p0 installed (which was the version I wanted to use) but in /usr/ i had ruby1.8.7 installed.

在 /usr/local/ 我安装了 ruby​​1.9.2-p0(这是我想使用的版本)但在 /usr/ 我安装了 ruby​​1.8.7。

Passenger was confused which ruby version to use so I changed the LoadModule, PassengerRoot and PassengerRuby paths within apache2/mods-enabled/passenger.load and .config to the correct paths and it finally worked! Both files were created automatically which also caused the problem of a redefinition: On apache startup there was a warning 'mod_passenger already loaded'. So I removed

乘客对使用哪个 ruby​​ 版本感到困惑,所以我将 apache2/mods-enabled/passenger.load 和 .config 中的 LoadModule、PassengerRoot 和PassengerRuby 路径更改为正确的路径,终于成功了!这两个文件都是自动创建的,这也导致了重新定义的问题:在 apache 启动时出现警告“mod_passenger already loaded”。所以我删除了

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

from the apache config and the warning disappeared!

从 apache 配置和警告消失了!

Probably this will help someone else some day!

也许有一天这会帮助别人!

回答by superluminary

The reason mod_passenger.so does not exist is because you haven't installed the Apache module. Execute:

mod_passenger.so 不存在的原因是你还没有安装 Apache 模块。执行:

passenger-install-apache2-module

This will create the mod_passenger.so file inside your gem directory, and give you three lines to copy into your apache2.conf file.

这将在您的 gem 目录中创建 mod_passenger.so 文件,并为您提供三行以复制到您的 apache2.conf 文件中。

The passenger module is installed in your current gemset so you shouldn't get any conflicts between projects. You can use any compatible version of Ruby, and any gemset you like, via RVM, and possibly also RBENV. This makes for a nice easy upgrade path from one version of Ruby to the next.

乘客模块安装在您当前的 gemset 中,因此您不应该在项目之间发生任何冲突。您可以通过 RVM 使用任何兼容版本的 Ruby 和任何您喜欢的 gemset,也可以使用 RBENV。这为从一个 Ruby 版本到下一个版本提供了一个很好的简单升级路径。

回答by Anwar

I have come across a cleaner solution today. This might help future users. The command -

我今天遇到了一个更清洁的解决方案。这可能会对未来的用户有所帮助。命令 -

passenger-install-apache2-module

tells me to put these three lines in apache configuration file.

告诉我将这三行放在 apache 配置文件中。

LoadModule passenger_module /home/anwar/.rvm/gems/ruby-2.2.0/gems/passenger-4.0.59/buildout/apache2/mod_passenger.so
   <IfModule mod_passenger.c>
     PassengerRoot /home/anwar/.rvm/gems/ruby-2.2.0/gems/passenger-4.0.59
     PassengerDefaultRuby /home/anwar/.rvm/gems/ruby-2.2.0/wrappers/ruby
   </IfModule>

But, where is that configuration file? The answer is the configuration files are seperated into many piecesand they reside in /etc/apache2/mods-available.

但是,那个配置文件在哪里?答案是配置文件被分成许多部分,它们驻留在/etc/apache2/mods-available.

So you should do three things -

所以你应该做三件事——

  1. Create a file ending with .loadin /etc/apache2/mods-availablefolder. I used passenger.load.

  2. Paste the three lines in that file and save the file.

  3. Now in terminal use sudo a2enmod <module-conf-filename>to enable the module. In my case, the file was, passenger.load. So, I used

    sudo a2enmod passenger
    
  1. 创建一个以文件夹结尾.load/etc/apache2/mods-available文件。我用过passenger.load

  2. 将三行粘贴到该文件中并保存该文件。

  3. 现在在终端中使用sudo a2enmod <module-conf-filename>以启用该模块。就我而言,该文件是passenger.load. 所以,我用

    sudo a2enmod passenger
    

Now, restart the server and use the command apache2ctl -Mto find that passengermodule is enabled.

现在,重新启动服务器并使用该命令apache2ctl -M查找该passenger模块已启用。

回答by dpb

I think they want you to put those three lines in your httpd.conf file, not in your apache2.conf. At least that's how I've always done it.

我认为他们希望您将这三行放在 httpd.conf 文件中,而不是放在 apache2.conf 中。至少我一直都是这样做的。