简体   繁体   English

在 Apache 上设置 Rails 应用程序与乘客 - Rails 似乎没有加载

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

I am trying to set up Rails on a Ubuntu instance by following along with documentation such as https://help.ubuntu.com/community/RubyOnRails .我正在尝试按照https://help.ubuntu.com/community/OnRails Ruby等文档在 Ubuntu 实例上设置 Rails。 I am trying to set up the app from the Rails Getting Started page here: http://guides.rubyonrails.org/getting_started.html .我正在尝试从 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)通过 RVM 和 GEM 安装 Ruby/RubyGems/Rails(这里安装了 Ruby 1.9.2 和 Rails 3.0.7)
  • Installation of the mysql and mysql2 module (latter which didn't work)安装 mysql 和 mysql2 模块(后者不起作用)
  • Creation of rails app (blog app as tutorial is instructing)创建 rails 应用程序(博客应用程序作为教程指导)
  • Sym linking of /home/me/www/blog/public/ from /var/www/blog/ /home/me/www/blog/public/ 的符号链接来自 /var/www/blog/
  • Creation of DB through rake通过 rake 创建 DB
  • Installation of passenger module for Rails execution in Apache在 Apache 中安装用于 Rails 执行的乘客模块
  • Running of passenger-install-apache2-module to configure Apache运行passenger-install-apache2-module来配置Apache
  • Deletion of public.html file from public/ rails app folder so that my controller/view can fire从 public/rails app 文件夹中删除 public.html 文件,以便我的控制器/视图可以触发
  • Configuration of sites-available files for virtual hosts为虚拟主机配置站点可用文件
  • Configuration of Rails routing 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.在我的虚拟主机文件中,我试图指向 /var/www/blog 中的博客公共目录。 For my Rails route I have root:to => "home#index" as instructed.对于我的 Rails 路线,我按照说明使用了root:to => "home#index"

When I browse to the http:// url I should normally be seeing my "Hello, Rails."当我浏览到 http://url 时,我通常应该看到我的“你好,Rails”。 page per section 4,3 of the Getting Started guide.按照入门指南第 4,3 节的第 4,3 页。 however all I see is the directory listing from Apache.但是我看到的只是 Apache 的目录列表。 Static pages work but not Rails processing. Static 页面可以工作,但 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.从那以后,我已经确定这个 cgi 404 是由我从帮助的指导中添加到 .htaccess 的重写规则引起的。我在上面指出的页面。 Looks like it wasn't necessary or applied to an older version of Rails.看起来它没有必要或应用于旧版本的 Rails。 The inconsistencies in instructions when looking up help online is disorienting.在线查找帮助时指令的不一致令人迷惑。 Removing the file leaves me with the previous problem though.删除文件让我遇到了之前的问题。

Here's the entry in the Apache log that I believe correlates with the first error.这是我认为与第一个错误相关的 Apache 日志中的条目。 Although I am no longer getting this error it seems, may be related to something else I was trying before...尽管我似乎不再收到此错误,但可能与我之前尝试过的其他事情有关...

[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.另一个更新:最后,通过使用顶级 DocumentRoot (/var/www) 并基于 Rails 应用程序使用 RailsBaseURI,我能够让它工作。 This maps to the "Deploying to a sub URI" section of the Phusion Passenger instructions.这映射到 Phusion 乘客指令的“部署到子 URI”部分。 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.它被用作 http:///blog 这并不是我真正想要的,但这有点无关紧要,因为我只是在虚拟中学习 Rails。 I will need to go and work on getting it working as a top level app again sometime later.我将需要 go 并努力让它在稍后的某个时间再次作为顶级应用程序运行。 Here's my current (final) VirtualHost file for reference:这是我当前(最终)的 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>

Deploying a Ruby on Rails application在 Rails 应用程序上部署 Ruby

Suppose you have a Ruby on Rails application in /webapps/mycook, and you own the domain www.mycook.com.假设您在 /webapps/mycook 中有一个 Ruby on Rails 应用程序,并且您拥有域 www.mycook.com。 You can either deploy your application to the virtual host's root (ie the application will be accessible from the root URL, http://www.mycook.com/ ), or in a sub URI (ie the application will be accessible from a sub URL, such as http://www.mycook.com/railsapplication ).您可以将应用程序部署到虚拟主机的根目录(即应用程序可以从根目录 URL、 http://www.mycook.com/访问),或者在子 URI 中(即应用程序可以从子目录访问) URL,如http://www.mycook.com/railsapplication )。

Deploying to a virtual host's root部署到虚拟主机的根

Add a virtual host entry to your Apache configuration file.将虚拟主机条目添加到 Apache 配置文件中。 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.虚拟主机的文档根目录必须指向您的 Ruby on Rails 应用程序的公共文件夹。
  • The Apache per-directory permissions must allow access to this folder. Apache 每个目录的权限必须允许访问此文件夹。
  • MultiViews must be disabled for this folder.必须为此文件夹禁用 MultiViews。

For example:例如:

<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:确保 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.也就是说,/webapps/mycook 和 /webapps 也必须是 Apache 可读和可执行的。

Then restart Apache.然后重启Apache。 The application has now been deployed.现在已经部署了应用程序。

Read the whole docs here此处阅读整个文档

Double check to make sure passenger is loading your application by typing sudo passenger-status通过键入 sudo Passenger-status 仔细检查以确保乘客正在加载您的应用程序

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

Be sure to delete the file index.html from the public directory of your application.请务必从应用程序的public目录中删除文件index.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM