Ruby-on-rails 使用乘客在 Apache 上设置 Rails 应用程序 - Rails 似乎没有加载

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6162196/
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:15:29  来源:igfitidea点击:

Setting up Rails app on Apache with passenger - Rails doesn't seem to load

ruby-on-railsrubyruby-on-rails-3apachepassenger

提问by Episcopus

I am trying to set up Rails on a Ubuntu instance by following along with documentation such as https://help.ubuntu.com/community/RubyOnRails. I am trying to set up the app from the Rails Getting Started page here: http://guides.rubyonrails.org/getting_started.html.

我正在尝试按照https://help.ubuntu.com/community/RubyOnRails等文档在 Ubuntu 实例上设置 Rails 。我正在尝试从此处的 Rails 入门页面设置应用程序:http: //guides.rubyonrails.org/getting_started.html

What I have done so far:

到目前为止我做了什么:

  • Installation of Ruby/RubyGems/Rails through RVM and GEM (this installed Ruby 1.9.2 and Rails 3.0.7)
  • Installation of the mysql and mysql2 module (latter which didn't work)
  • Creation of rails app (blog app as tutorial is instructing)
  • Sym linking of /home/me/www/blog/public/ from /var/www/blog/
  • Creation of DB through rake
  • Installation of passenger module for Rails execution in Apache
  • Running of passenger-install-apache2-moduleto configure Apache
  • Deletion of public.html file from public/ rails app folder so that my controller/view can fire
  • Configuration of sites-available files for virtual hosts
  • Configuration of Rails routing
  • 通过 RVM 和 GEM 安装 Ruby/RubyGems/Rails(这里安装了 Ruby 1.9.2 和 Rails 3.0.7)
  • 安装 mysql 和 mysql2 模块(后者不起作用)
  • 创建 rails 应用程序(作为教程指导的博客应用程序)
  • /home/me/www/blog/public/ 的符号链接来自 /var/www/blog/
  • 通过 rake 创建 DB
  • 在 Apache 中安装用于 Rails 执行的乘客模块
  • 运行passenger-install-apache2-module配置Apache
  • 从 public/ rails app 文件夹中删除 public.html 文件,以便我的控制器/视图可以触发
  • 为虚拟主机配置站点可用文件
  • Rails 路由的配置

I believe it is the last two steps that are tripping me up, partly due to lack of familiarity with Apache and Rails (I am new to both).

我相信是最后两个步骤让我绊倒了,部分原因是不熟悉 Apache 和 Rails(我对这两个都是新手)。

In my virtual host file I am trying to point to the blog public dir in /var/www/blog. For my Rails route I have root :to => "home#index"as instructed.

在我的虚拟主机文件中,我试图指向 /var/www/blog 中的博客公共目录。对于我的 Rails 路线,我已root :to => "home#index"按照指示进行。

When I browse to the http:// url I should normally be seeing my "Hello, Rails!" page per section 4.3 of the Getting Started guide, however all I see is the directory listing from Apache. Static pages work but not Rails processing.

当我浏览到 http:// url 时,我通常应该看到我的“Hello, Rails!” 入门指南第 4.3 节的页面,但是我看到的只是来自 Apache 的目录列表。静态页面有效,但 Rails 处理无效。

At this point I am unclear if the passenger module is even doing anything or where to look for any evidence of what is happening. I tried various things like running the Rails app off a different virtual host called "blog" at http:///blog and the routing worked (static pages and all) but no Rails as above.

在这一点上,我不清楚乘客模块是否在做任何事情,或者在哪里寻找正在发生的事情的任何证据。我尝试了各种方法,例如在 http:///blog 上名为“blog”的不同虚拟主机上运行 Rails 应用程序,并且路由工作(静态页面和所有页面),但没有如上所示的 Rails。

Update: after playing around some more, I now get a new error message (404):

更新:在玩了更多之后,我现在收到一条新的错误消息(404):

Not Found

The requested URL /dispatch.cgi was not found on this server.

未找到

在此服务器上找不到请求的 URL /dispatch.cgi。

I have since determined that this cgi 404 was caused by a rewrite rule I had added to .htaccess from guidance from the help.ubuntu.com page I pointed out above. Looks like it wasn't necessary or applied to an older version of Rails. The inconsistencies in instructions when looking up help online is disorienting! Removing the file leaves me with the previous problem though.

从那以后,我确定这个 cgi 404 是由我根据上面指出的 help.ubuntu.com 页面的指导添加到 .htaccess 的重写规则引起的。看起来它没有必要或应用于旧版本的 Rails。在线查找帮助时的说明不一致令人迷惑!但是,删除文件使我遇到了以前的问题。

Here's the entry in the Apache log that I believe correlates with the first error. Although I am no longer getting this error it seems, may be related to something else I was trying before...

这是我认为与第一个错误相关的 Apache 日志中的条目。虽然我似乎不再收到此错误,但可能与我之前尝试过的其他事情有关...

[Fri May 27 22:49:41 2011] [notice] Apache/2.2.16 (Ubuntu) PHP/5.3.3-1ubuntu9 with Suhosin-Patch Phusion_Passenger/3.0.7 configured -- resuming normal operations
[Fri May 27 22:51:18 2011] [error] [client 192.168.1.141] File does not exist: /var/www/blog/rails, referer: http://192.168.1.138/blog/

Here's the most recent entry with the 404 on the cgi thing:

这是关于 cgi 事物的 404 的最新条目:

[Sat May 28 08:01:18 2011] [error] [client 192.168.1.141] File does not exist: /var/www/blog/dispatch.cgi

What could I be missing? Thanks!

我可能会错过什么?谢谢!



Additional details as requested. Apache sites file:

根据要求提供其他详细信息。Apache 站点文件:

<VirtualHost *:80>
        ServerAdmin webmaster@localhost

        DocumentRoot /var/www/blog/
    RailsEnv development

        # <Directory />
        #       Options FollowSymLinks
        #       AllowOverride None
        # </Directory>

        <Directory "/var/www/blog/">
        Options Indexes FollowSymLinks -MultiViews +ExecCGI
                AllowOverride All
                Order allow,deny
                allow from all
        # AddHandler cgi-script .cgi
        </Directory>

        ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
    <Directory "/usr/lib/cgi-bin">
                AllowOverride None
                Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
                Order allow,deny
                Allow from all
        </Directory>

        ErrorLog ${APACHE_LOG_DIR}/error.log

        # Possible values include: debug, info, notice, warn, error, crit,
        # alert, emerg.
        LogLevel warn

        CustomLog ${APACHE_LOG_DIR}/access.log combined

    Alias /doc/ "/usr/share/doc/"
    <Directory "/usr/share/doc/">
        Options Indexes MultiViews FollowSymLinks
    AllowOverride None
        Order deny,allow
        Deny from all
        Allow from 127.0.0.0/255.0.0.0 ::1/128
    </Directory>

</VirtualHost>

Another update:I was able to get it working, finally, by using a top level DocumentRoot (/var/www) and basing my Rails app off that using RailsBaseURI. This maps to the "Deploying to a sub URI" section of the Phusion Passenger instructions. It is used as http:///blog which is not really what I wanted to get, but it's kind of irrelevant as I am using this just to learn Rails in a virtual. I will need to go and work on getting it working as a top level app again sometime later. Here's my current (final) VirtualHost file for reference:

另一个更新:最后,通过使用顶级 DocumentRoot (/var/www) 并使用 RailsBaseURI 将我的 Rails 应用程序作为基础,我能够让它工作。这映射到 Phusion 乘客说明的“部署到子 URI”部分。它被用作 http:///blog 这并不是我真正想要得到的,但这有点无关紧要,因为我使用它只是为了在虚拟环境中学习 Rails。稍后我将需要继续努力使其作为顶级应用程序再次运行。这是我当前的(最终)VirtualHost 文件以供参考:

<VirtualHost *:80>
        ServerAdmin webmaster@localhost

        DocumentRoot /var/www/
        RailsEnv development

        <Directory /var/www/>
          Options FollowSymLinks
          AllowOverride None
        </Directory>

    RailsBaseURI /blog
        <Directory /var/www/blog/>
                Options Indexes FollowSymLinks -MultiViews +ExecCGI
                AllowOverride All
                Order allow,deny
                allow from all
                # AddHandler cgi-script .cgi
        </Directory>

        ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
        <Directory "/usr/lib/cgi-bin">
                AllowOverride None
                Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
                Order allow,deny
                Allow from all
        </Directory>

        ErrorLog ${APACHE_LOG_DIR}/error.log

        # Possible values include: debug, info, notice, warn, error, crit,
        # alert, emerg.
        LogLevel warn

        CustomLog ${APACHE_LOG_DIR}/access.log combined

    Alias /doc/ "/usr/share/doc/"
    <Directory "/usr/share/doc/">
        Options Indexes MultiViews FollowSymLinks
        AllowOverride None
        Order deny,allow
        Deny from all
        Allow from 127.0.0.0/255.0.0.0 ::1/128
    </Directory>

</VirtualHost>

回答by MarioRicalde

Deploying a Ruby on Rails application

Suppose you have a Ruby on Rails application in /webapps/mycook, and you own the domain www.mycook.com. You can either deploy your application to the virtual host's root (i.e. the application will be accessible from the root URL, http://www.mycook.com/), or in a sub URI (i.e. the application will be accessible from a sub URL, such as http://www.mycook.com/railsapplication).

Deploying to a virtual host's root

Add a virtual host entry to your Apache configuration file. Make sure that the following conditions are met:

  • The virtual host's document root must point to your Ruby on Rails application's public folder.
  • The Apache per-directory permissions must allow access to this folder.
  • MultiViews must be disabled for this folder.

For example:

部署 Ruby on Rails 应用程序

假设您在 /webapps/mycook 中有一个 Ruby on Rails 应用程序,并且您拥有域 www.mycook.com。您可以将应用程序部署到虚拟主机的根目录(即可以从根 URL http://www.mycook.com/访问该应用程序),或在子 URI 中(即可以从子 URI 访问该应用程序) URL,例如 http://www.mycook.com/railsapplication)。

部署到虚拟主机的根目录

将虚拟主机条目添加到 Apache 配置文件。确保满足以下条件:

  • 虚拟主机的文档根目录必须指向 Ruby on Rails 应用程序的公共文件夹。
  • Apache per-directory 权限必须允许访问此文件夹。
  • 必须为此文件夹禁用多视图。

例如:

<VirtualHost *:80>
    ServerName www.mycook.com
    DocumentRoot /webapps/mycook/public
    <Directory /webapps/mycook/public>
        Allow from all
        Options -MultiViews
    </Directory>
</VirtualHost>

You may also need to tweak your file/folder permissions. Make sure that the following folders are readable and executable by Apache:

  • this public folder.
  • the application's config folder.
  • all parent folders. That is, /webapps/mycook and /webapps must also be readable and executable by Apache.

Then restart Apache. The application has now been deployed.

您可能还需要调整您的文件/文件夹权限。确保 Apache 可以读取和执行以下文件夹:

  • 这个公用文件夹。
  • 应用程序的配置文件夹。
  • 所有父文件夹。也就是说,/webapps/mycook 和 /webapps 也必须是 Apache 可读和可执行的。

然后重新启动Apache。现在已经部署了应用程序。

Read the whole docs here

这里阅读整个文档

回答by Rourke

Double check to make sure passenger is loading your application by typing sudo passenger-status

通过输入 sudo 乘客状态仔细检查以确保乘客正在加载您的应用程序

This will show you an error if passenger isn't loaded or the below if it is. Note the part where it shows you which application or applications it has loaded and what the current uptime is:

如果没有载客,这将向您显示错误,如果载有,则会显示以下错误。请注意它向您显示已加载的一个或多个应用程序以及当前正常运行时间的部分:

----------- General information -----------
max      = 6
count    = 1
active   = 0
inactive = 1
Waiting on global queue: 0
----------- Application groups -----------
/home/rourkem/public_html/evecord.com/current:
  App root: /home/rourkem/public_html/evecord.com/current
  * PID: 18976   Sessions: 0    Processed: 5       Uptime: 23m 55s

回答by Andrew Nesbitt

Be sure to delete the file index.htmlfrom the publicdirectory of your application.

请务必index.htmlpublic应用程序目录中删除该文件。