我需要一些帮助来获得在cPanel配置的Apache站点的子uri中工作的Rails 3.2应用程序。我已经按照Passenger docs和各种博客文章的步骤进行了操作。根操作渲染得很好,但每个其他请求都给我一个404。
我认为它是Apache中的东西,而不是Rails,配置,因为它不是Rails应用程序的404页面,而且404s不会在Rails日志中留下痕迹。
这是来自httpd.conf的vhost部分,由cPanel生成:
<VirtualHost myip:443>
ServerName mysite.org
ServerAlias www.mysite.org
DocumentRoot /home/myuser/public_html
ServerAdmin webmaster@mysite.org
UseCanonicalName Off
Options -ExecCGI -Includes
RemoveHandler cgi-script .cgi .pl .plx .ppl .perl
CustomLog /usr/local/apache/domlogs/mysite.org combined
CustomLog /usr/local/apache/domlogs/mysite.org-bytes_log "%{%s}t %I .\n%{%s}t %O ."
## User myuser # Needed for CPanel::ApacheConf
UserDir disabled
UserDir enabled myuser
<IfModule mod_suphp.c>
suPHP_UserGroup myuser myuser
</IfModule>
<IfModule !mod_disable_suexec.c>
<IfModule !mod_ruid2.c>
SuexecUserGroup myuser myuser
</IfModule>
</IfModule>
<IfModule mod_ruid2.c>
RUidGid myuser myuser
</IfModule>
SSLEngine on
SSLCertificateFile /etc/ssl/certs/mysite.org.crt
SSLCertificateKeyFile /etc/ssl/private/mysite.org.key
SSLCACertificateFile /etc/ssl/certs/mysite.org.cabundle
CustomLog /usr/local/apache/domlogs/mysite.org-ssl_log combined
SetEnvIf User-Agent ".*MSIE.*" nokeepalive ssl-unclean-shutdown
<Directory "/home/myuser/public_html/cgi-bin">
SSLOptions +StdEnvVars
</Directory>
Include "/usr/local/apache/conf/userdata/ssl/2/myuser/mysite.org/*.conf"
</VirtualHost>
以下是我为子uri放在一起的包含文件的当前版本:
RewriteEngine On
RewriteOptions Inherit
RailsEnv production
<Directory /home/myuser/public_html>
Options Indexes FollowSymLinks -MultiViews
AllowOverride all
Order allow,deny
Allow from all
</Directory>
RackBaseURI /home/myrailsapp/current
<Directory /home/myuser/public_html/railsapp>
Options -MultiViews
</Directory>
/ home / myuser / public_html / railsapp是/ home / myrailsapp / current / public的符号链接
这是/home/myrailsapp/current/public/.htaccess
RackBaseURI /railsapp
SetEnv GEM_HOME /usr/local/lib/ruby/gems
PassengerEnabled On
PassengerAppRoot /home/myrailsapp/current/
/ home / myrailsapp和/ home / mysite中的所有文件都归myuser所有。 (我没有看到任何权限错误。)
在我的路线档案中:
resources :widgets
root :to => 'widgets#index'
当我导航到https://mysite.org/railsapp时,它会正确显示小部件索引,包括资产。当我转到https://mysite.org/railsapp/widgets或https://mysite.org/railsapp/widgets/index时,我得到了Apache 404,并且在Rails日志中没有任何条目。
我错过了什么?
答案 0 :(得分:1)
事实证明,/ home / myuser / public_html中的.htaccess正在重写所有内容。对/ mysite / railsapp的请求被豁免,因为它与目录名称匹配。我通过添加
解决了这个问题RewriteEngine off
到/home/myrailsapp/current/public/.htaccess。
答案 1 :(得分:1)
将RewriteEngine off
添加到.htaccess
确实可以解决问题。