使用乘客在 Apache 上设置 Rails 应用程序 - Rails 似乎没有加载 [英] Setting up Rails app on Apache with passenger - Rails doesn't seem to load

查看:28
本文介绍了使用乘客在 Apache 上设置 Rails 应用程序 - Rails 似乎没有加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

到目前为止我所做的:

  • 通过 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 创建数据库
  • 在 Apache 中安装用于 Rails 执行的乘客模块
  • 运行passenger-install-apache2-module来配置Apache
  • 从 public/rails app 文件夹中删除 public.html 文件,以便我的控制器/视图可以触发
  • 为虚拟主机配置站点可用文件
  • Rails 路由的配置

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

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

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

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

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

<块引用>

未找到

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

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

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

[Fri May 27 22:49:41 2011] [notice] Apache/2.2.16 (Ubuntu) PHP/5.3.3-1ubuntu9 配置 Suhosin-Patch Phusion_Passenger/3.0.7 -- 恢复正常操作[2011 年 5 月 27 日星期五 22:51:18] [错误] [客户端 192.168.1.141] 文件不存在:/var/www/blog/rails,referer:http://192.168.1.138/blog/

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

[Sat May 28 08:01:18 2011] [error] [client 192.168.1.141] 文件不存在:/var/www/blog/dispatch.cgi

我会错过什么?谢谢!

<小时>

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

ServerAdmin 站长@localhostDocumentRoot/var/www/blog/RailsEnv 开发# <目录/># 选项 FollowSymLinks# AllowOverride 无# </目录><目录/var/www/blog/">选项索引 FollowSymLinks -MultiViews +ExecCGI允许覆盖所有命令允许,拒绝允许所有人# AddHandler cgi-script .cgi</目录>脚本别名/cgi-bin//usr/lib/cgi-bin/<目录/usr/lib/cgi-bin">允许覆盖无选项 +ExecCGI -MultiViews +SymLinksIfOwnerMatch命令允许,拒绝所有人都允许</目录>错误日志 ${APACHE_LOG_DIR}/error.log# 可能的值包括:调试、信息、通知、警告、错误、暴击、# 警报,紧急.日志级别警告CustomLog ${APACHE_LOG_DIR}/access.log 合并别名/doc/"/usr/share/doc/"<目录/usr/share/doc/">选项索引多视图 FollowSymLinks允许覆盖无订单拒绝,允许拒绝所有人允许来自 127.0.0.0/255.0.0.0 ::1/128</目录></虚拟主机>

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

ServerAdmin 站长@localhost文档根目录/var/www/RailsEnv 开发<目录/var/www/>选项 FollowSymLinks允许覆盖无</目录>RailsBaseURI/博客<目录/var/www/blog/>选项索引 FollowSymLinks -MultiViews +ExecCGI允许覆盖所有命令允许,拒绝允许所有人# AddHandler cgi-script .cgi</目录>脚本别名/cgi-bin//usr/lib/cgi-bin/<目录/usr/lib/cgi-bin">允许覆盖无选项 +ExecCGI -MultiViews +SymLinksIfOwnerMatch命令允许,拒绝所有人都允许</目录>错误日志 ${APACHE_LOG_DIR}/error.log# 可能的值包括:调试、信息、通知、警告、错误、暴击、# 警报,紧急.日志级别警告CustomLog ${APACHE_LOG_DIR}/access.log 合并别名/doc/"/usr/share/doc/"<目录/usr/share/doc/">选项索引多视图 FollowSymLinks允许覆盖无订单拒绝,允许拒绝所有人允许来自 127.0.0.0/255.0.0.0 ::1/128</目录></虚拟主机>

解决方案

部署 Ruby on Rails 应用程序

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

部署到虚拟主机的根目录

将虚拟主机条目添加到您的阿帕奇配置文件.确保满足以下条件:

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

例如:

服务器名称 www.mycook.comDocumentRoot/webapps/mycook/public<目录/webapps/mycook/public>所有人都允许选项 - 多视图</目录></虚拟主机>

<块引用>

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

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

然后重启Apache.应用程序现已部署.

此处

阅读整个文档

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.

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-module to 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

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).

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.

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.

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.

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

Not Found

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

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.

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...

[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:

[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:

<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:

<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

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:

<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.

Read the whole docs here

这篇关于使用乘客在 Apache 上设置 Rails 应用程序 - Rails 似乎没有加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆