客运在Apache设置的Rails应用程序 - Rails的似乎不加载 [英] Setting up Rails app on Apache with passenger - Rails doesn't seem to load

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

问题描述

我试图用文档按照顺序,如<一个建立在Ubuntu的实例的Rails href=\"https://help.ubuntu.com/community/RubyOnRails\">https://help.ubuntu.com/community/RubyOnRails.我试图建立应用程序上的Rails抵达该处开始页面:<一href=\"http://guides.rubyonrails.org/getting_started.html\">http://guides.rubyonrails.org/getting_started.html.

我迄今所做的:


  • 通过RVM和创业板(此安装了Ruby 1.9.2和Rails 3.0.7)红宝石/ RubyGems的/ Rails的安装

  • mysql和mysql2模块的安装(后者没有工作)

  • Rails应用程序的创建(博客应用的教程指导)

  • 的符号链接/家庭/ ME / WWW /博客/公/在/ var / WWW /博客/

  • 通过耙DB的创建

  • 乘客模块的安装Rails的执行Apache中

  • 的运行乘客安装-Apache2的模块来配置Apache

  • 从公共public.html文件的删除/ Rails应用程序文件夹,这样我的控制器/视图可以开火

  • 网站可用文件的虚拟主机配置

  • 的Rails配置路由

我相信它是被绊倒了我的最后两个步骤,部分原因是由于缺乏与Apache和Rails熟悉的(我是新来的这两种)。

在我的虚拟主机文件我想指出在/ var / WWW /博客的博客公开目录。对于我的Rails的路线我有根:给= GT; 家#指数的指示。

当我浏览到HTTP:// URL我通常应该是看到我的你好,Rails的!每款入门指南的4.3页,但我看到的是Apache的目录列表。静态页面的工作,但不是Rails的处理。

在这一点上我不清楚如果乘客模块甚至做任何事情,或去哪里寻找正在发生的事情的任何证据。我尝试了各种类似的事情在http运行Rails应用程序关闭所谓的博客不同的虚拟主机:///博客和路由工作(静态页面和所有),但正如上面没有任何的Rails

更新:各地一些上场后,我现在得到一个新的错误信息(404):


  

未找到


  
  

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


因为我已经决定这个CGI 404是由我已经添加了从指导的.htaccess从help.ubuntu.com页我上面指出的一个重写规则造成的。看起来就像是没有必要或不适用的旧版本的Rails。查找在线帮助时说明不一致是迷惑!删除文件给我留下的previous问题,但

下面是在Apache进入日志,我认为与第一个错误相关。虽然我不再收到此错误现在看来,可能与另外我之前想的东西...

  [周五5月27日22点49分41秒2011] [声明]的Apache / 2.2.16(Ubuntu的)PHP / 5.3.3-1ubuntu9用了Suhosin-补丁Phusion_Passenger / 3.0.7配置 - 恢复正常运作
[周五5月27日22时51分18秒2011] [错误] [客户端192.168.1.141]文件不存在:在/ var / WWW /博客/导轨,引用者:http://192.168.1.138/blog/

下面是对CGI的事情最新的条目与404:

  [周六5月28日8时01分18秒2011] [错误] [客户端192.168.1.141]文件不存在:/var/www/blog/dispatch.cgi

我能怎么会失踪?谢谢!


其他细节的要求。 Apache的网站上的文件:

 &LT;虚拟主机*:80&GT;
        站长的ServerAdmin @本地        的DocumentRoot的/ var / WWW /博客/
    RailsEnv发展        #&LT;目录/&GT;
        #有FollowSymLinks
        #设置AllowOverride无
        #&LT; /目录&GT;        &LT;目录/无功/网络/博客/&GT;
        选择了FollowSymLinks索引+ -MultiViews ExecCGI
                所有的AllowOverride
                为了允许,拒绝
                所有允许
        #AddHandler的CGI脚本的CGI
        &LT; /目录&GT;        ScriptAlias​​指令/的cgi-bin / / usr / lib目录/ cgi-bin目录/
    &LT;目录/ usr / lib目录/ cgi-bin目录&GT;
                设置AllowOverride无
                选项​​+ ExecCGI -MultiViews + SymLinksIfOwnerMatch
                为了允许,拒绝
                所有允许
        &LT; /目录&GT;        错误日志$ {} APACHE_LOG_DIR /error.log        #可能的值包括:调试,信息,通知,警告,错误,暴击,
        #警报,EMERG。
        LOGLEVEL警告        的CustomLog $ {} APACHE_LOG_DIR结合/access.log    别名/ DOC /的/ usr /共享/ DOC /
    &LT;目录的/ usr /共享/ DOC /&GT;
        选择多视图索引了FollowSymLinks
    设置AllowOverride无
        为了否认,允许
        所有拒绝
        从127.0.0.0/255.0.0.0允许:: 1/128
    &LT; /目录&GT;&LT; /虚拟主机&GT;

另一个更新:我能得到它的工作,最后,用一个顶级的DocumentRoot(在/ var / WWW)和基础我的Rails应用程序关闭,使用RailsBaseURI。这映射到的Phusion的乘客说明部署到子URI一节。它是用来为http:///博客里面是不是真的是我想要得到的,但它是我用这只是为了学习的Rails在虚拟有点无关紧要。我需要去得到它的工作作为一个顶级的应用程序再次晚些时候工作。这是我目前的(最终)虚拟主机文件,以供参考:

 &LT;虚拟主机*:80&GT;
        站长的ServerAdmin @本地        的DocumentRoot的/ var / WWW /
        RailsEnv发展        &LT;目录/ var / WWW /&GT;
          有FollowSymLinks
          设置AllowOverride无
        &LT; /目录&GT;    RailsBaseURI /博客
        &LT;目录/ var / WWW /博客/&GT;
                选择了FollowSymLinks索引+ -MultiViews ExecCGI
                所有的AllowOverride
                为了允许,拒绝
                所有允许
                #AddHandler的CGI脚本的CGI
        &LT; /目录&GT;        ScriptAlias​​指令/的cgi-bin / / usr / lib目录/ cgi-bin目录/
        &LT;目录/ usr / lib目录/ cgi-bin目录&GT;
                设置AllowOverride无
                选项​​+ ExecCGI -MultiViews + SymLinksIfOwnerMatch
                为了允许,拒绝
                所有允许
        &LT; /目录&GT;        错误日志$ {} APACHE_LOG_DIR /error.log        #可能的值包括:调试,信息,通知,警告,错误,暴击,
        #警报,EMERG。
        LOGLEVEL警告        的CustomLog $ {} APACHE_LOG_DIR结合/access.log    别名/ DOC /的/ usr /共享/ DOC /
    &LT;目录的/ usr /共享/ DOC /&GT;
        选择多视图索引了FollowSymLinks
        设置AllowOverride无
        为了否认,允许
        所有拒绝
        从127.0.0.0/255.0.0.0允许:: 1/128
    &LT; /目录&GT;&LT; /虚拟主机&GT;


解决方案

  

部署Ruby on Rails应用


  
  

假设你有on Rails的Ruby的
  在应用/ webapps /下mycook和
  你自己的域名www.mycook.com。您
  可以将应用程序部署到
  虚拟主机的根目录(即
  应用程序将是访问
  根URL, http://www.mycook.com/
  或者在子的URI(即,应用程序
  将是可访问从子网址
  如
   http://www.mycook.com/railsapplication )。


  
  

部署到虚拟主机的根


  
  

添加一个虚拟主机条目您
  Apache配置文件。确保
  下列条件:


  
  

      
  • 的虚拟主机的文档根绝
      指向您的Ruby on Rails的
      应用程序的公用文件夹。

  •   
  • Apache的每个目录的权限
      必须允许访问此文件夹。

  •   
  • 多视图必须为此被禁用
      文件夹中。

  •   

  
  

例如:


 &LT;虚拟主机*:80&GT;
    服务器名www.mycook.com
    的DocumentRoot / webapps /下mycook /公
    &LT;目录/ webapps /下mycook /公共&GT;
        所有允许
        选项​​-MultiViews
    &LT; /目录&GT;
&LT; /虚拟主机&GT;


  

您可能还需要调整
  文件/文件夹的权限。确保
  下列文件夹
  可读和可执行阿帕奇:


  
  

      
  • 此公用文件夹。

  •   
  • 应用程序的config文件夹。

  •   
  • 所有父文件夹。也就是说,/ webapps /下mycook和/ webapps中还必须
      由阿帕奇可读和可执行。

  •   

  
  

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


阅读整篇文档<一个href=\"http://www.modrails.com/documentation/Users%20guide%20Apache.html#_deploying_a_ruby_on_rails_application\">here

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天全站免登陆