使用乘客在 Apache 上设置 Rails 应用程序 - Rails 似乎未加载

发布于 2024-11-10 16:16:41 字数 5064 浏览 7 评论 0原文

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

到目前为止我所做的:

  • 通过RVM和GEM安装Ruby/RubyGems/Rails(这安装了Ruby 1.9.2和Rails 3.0.7)
  • 安装mysql和mysql2模块(后者不起作用)
  • 创建rails应用程序(教程中的博客应用程序正在指导)
  • 从 /var/www/blog/ 链接 /home/me/www/blog/public/
  • 通过 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 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/

这是 cgi 上 404 的最新条目:

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

我可能会缺少什么?谢谢!


根据要求提供更多详细信息。 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>

另一个更新: 最后,通过使用顶级 DocumentRoot (/var/www) 并使用 RailsBaseURI 将我的 Rails 应用程序建立在其基础上,我能够使其正常工作。这映射到 Phusion Passenger 说明的“部署到子 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>

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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

转身以后 2024-11-17 16:16:41

部署 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 每个目录的权限
    必须允许访问此文件夹。
  • 为此必须禁用多视图
    文件夹。

例如:

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

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

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

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

此处阅读整个文档

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

那支青花 2024-11-17 16:16:41

仔细检查以确保乘客正在通过键入内容加载您的申请表
sudo Passenger-status

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

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

Double check to make sure passenger is loading your application by typing
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
也只是曾经 2024-11-17 16:16:41

请务必从应用程序的 public 目录中删除文件 index.html

Be sure to delete the file index.html from the public directory of your application.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文