jeem
jeem

Reputation: 919

Trouble configuring a sub-uri with Apache 2, Rails 3.2, and Phusion Passenger

I need some help getting a Rails 3.2 app working in a sub-uri of a cPanel-configured Apache site. I've followed the steps from the Passenger docs and various blog posts. The root action renders fine, but every other request gives me a 404.

I think it is something in the Apache, not Rails, config, because it's not the Rails app's 404 page, and the 404s do not leave traces in the Rails log.

Here is the vhost section from httpd.conf, generated by cPanel:

<VirtualHost myip:443>
    ServerName mysite.org
    ServerAlias www.mysite.org
    DocumentRoot /home/myuser/public_html
    ServerAdmin [email protected]
    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> 

Here is the current version of the include file I put together for the sub-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 is a symlink to /home/myrailsapp/current/public

Here is /home/myrailsapp/current/public/.htaccess

RackBaseURI /railsapp
SetEnv GEM_HOME /usr/local/lib/ruby/gems
PassengerEnabled On
PassengerAppRoot /home/myrailsapp/current/

All files in /home/myrailsapp and /home/mysite are owned by myuser. (I'm not seeing any permissions errors.)

In my routes file:

  resources :widgets
  root :to => 'widgets#index'

When I navigate to https://mysite.org/railsapp it correctly displays the widgets index, including assets. When I go to https://mysite.org/railsapp/widgets or https://mysite.org/railsapp/widgets/index, I get the Apache 404, and no entry in the Rails log.

What am I missing?

Upvotes: 2

Views: 822

Answers (2)

Raj
Raj

Reputation: 21

Adding RewriteEngine off to .htaccess does solve the problem.

Upvotes: 2

jeem
jeem

Reputation: 919

It turns out .htaccess in /home/myuser/public_html was rewriting everything. Requests for /mysite/railsapp were exempted because it matched a directory name. I solved the problem by adding

RewriteEngine off

to /home/myrailsapp/current/public/.htaccess.

Upvotes: 2

Related Questions