使用乘客在 Apache 上设置 Rails 应用程序 - Rails 似乎未加载
我正在尝试按照 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
此处阅读整个文档
Read the whole docs here
仔细检查以确保乘客正在通过键入内容加载您的申请表
sudo Passenger-status
如果未加载乘客,则会显示错误;如果已加载,则会显示以下错误。请注意它向您显示已加载的一个或多个应用程序以及当前正常运行时间的部分:
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:
请务必从应用程序的
public
目录中删除文件index.html
。Be sure to delete the file
index.html
from thepublic
directory of your application.