Public Directory not accessible

Been trying to deploy my rails app on Redhat ES3, Apache2, FastCGI with
Plesk all day. Fun stuff. Basically, the issue that I can not solve has
to do with access to /public. None of my images, javascripts, etc. are
working in the app. Trying to access any of these results in a 404 (or
routing error if in developer mode). Oddly, the 404 file it displays is
– you guessed it – in fact in the public directory.

Anyone else ever run into this?

Seriously? Nobody here has run into issues with inacessible /public
directories in Rails on Apache2/FastCGI?

I love being the first. :stuck_out_tongue:

Ryan W. wrote:

Seriously? Nobody here has run into issues with inacessible /public
directories in Rails on Apache2/FastCGI?

I love being the first. :stuck_out_tongue:

Can we get a little more info? Config files, error logs, things you’ve
tried so far, etc…

Can we get a little more info? Config files, error logs, things you’ve
tried so far, etc…

Sure. Sorry. There’s another LONG thread where I went though all that
stuff which I should have referenced. But to avoid confusion (I’ve
figured out many of those issues since), I’ll start clean.

I’m running on RedHat ES3 with Plesk 7.5.4 server management
Apache2 is installed at /usr/sbin/httpd
Ruby is at 1.8.4
Rails at 1.1.2
mod_fastcgi-2.4.2

Since I’m using Plesk to manage my hosting service, it has this nasty
habit of wanting to control things (like it was asked to do… go
figure). So, anything you write into httpd.conf gets overwritten on
reboot. You get around this by including additional .conf files in
/etc/httpd/conf.d/. So, I added the following fastcgi.conf:

User apache
Group apache
LoadModule fastcgi_module /usr/lib/httpd/modules/mod_fastcgi.so

FastCgiWrapper on FastCgiConfig -idle-timeout 900 FastCgiIpcDir /tmp/fastcgi_ipc/ AddHandler fastcgi-script .fcgi .rb FastCgiServer /home/httpd/vhosts/mydomain.com/httpdocs/myapp/dispatch.fcgi -idle-timeout 120 -initial-env RAILS_ENV=production -processes 4

The User and Group bit ends up being repeated in the httpd.conf, but it
is necessary since Redhat loads anything in conf.d before the user and
group declarations. Next, I make sure CGI is enabled for the domain in
Plesk settings (if not, suexec will try to run the script as apache or
root which results in an application that doesn’t respond. Spent HOURS
on that one!)

Okay, so I upload myapp (which is set to rake freeze_gems at 1.1.1 btw)
to the domain root (behind the www root). Chown -R to the correct domain
user:group and chmod everything 755. I create a symbolic link named
‘myapp’ in the web root pointed to …/myapp/public and make sure owner
is correct and it is chmod 777 as well. Then I go into
myapp/public/.htaccess and make sure the dispatch.fcgi is uncommented
and .cgi version is commented out. Next, I move over to myapp/config/ to
change environment.rb to production mode. Then double check my
database.yml settings to make sure they point at the MySQL databases.

All good stuff right?

We’ll cool, I can log into myapp! But wait! I have no images. That’s
odd. And double-wait! My javascript isn’t loading!! Oh no… all those
AJAX actions… DEAD! And stylesheets? What are those?? :slight_smile:

From that point, I start looking into logs. Oh heck… the apache
error_log has literally hundreds of these:

[Wed Apr 12 14:08:23 2006] [warn] FastCGI: server
“/home/httpd/vhosts/mydomain.com/httpdocs/myapp/dispatch.fcgi” has
failed to remain running for 30 seconds given 3 attempts, its restart
interval has been backed off to 600 seconds

And likewise, suexec_log:

[2006-04-12 14:08:23]: uid: (apache/apache) gid: (apache/apache) cmd:
dispatch.fcgi
[2006-04-12 14:08:23]: crit: cannot run as forbidden uid
(48/dispatch.fcgi)

Hmmm… odd that some of the app runs despite this. Only public is being
hosed (well, and my logs!).

Did a little more looking around and saw someone suggest to add the
following to /vendor/rails/railties/lib/fcgi_handler.rb:

require ‘rubygems’
require_gem ‘fcgi’

since I did indeed install the gems version.

killed any ruby processes, cleaned out /tmp/fastcgi_ipc/, deleted any
cookies for the domain and did apachectl -k graceful

Went to the site, logged in, still no joy on public dir access.
Greeeeat.

So, I’m at a complete loss. The only other thing I was about to try in
desperation to use mod_fcgid instead of mod_fastcgi. I don’t really see
how that would change anything with /public, but I’ll try anything at
this point.

Thanks for your time! Sorry so long!

Ryan

Have you posted the entire VirtualHost block yet? I looked through the
original thread and didn’t see it. I’m curious to see what you set your
DocumentRoot too, in particular, so maybe pasting in the whole block
will shed some light.

Also, I understand you can suexec your virtualhost as apache/apache
since it’s your machine and you can chown to it, but have you tested it
without the suexec and explicit user and group to rule that out as the
problem?

Ryan W. wrote:

Can we get a little more info? Config files, error logs, things you’ve
tried so far, etc…

Sure. Sorry. There’s another LONG thread where I went though all that
stuff which I should have referenced. But to avoid confusion (I’ve
figured out many of those issues since), I’ll start clean.

Well, I might be barking up the wrong tree with the /public directory’s
inaccessibility being a server config issue. I just opened one of those
cheapy GoDaddy accounts with Rails and uploaded my app. I get the exact
same behavior with them. /public is inaccessible. So, obviously, I must
be doing something intolerably stupid inside my app. Everything works
fine locally with WEBrick in development or production mode. I don’t get
what would be different in that regard with any FastCGI installation.

What would keep the public directory from being seen when not using
WEBrick?

Just FYI, here’s the bulk of my fastcgi and ViurtualHost config. It
might be helpful even though I’m not using suexec for this one.

Note the docroot set to the public dir, with no trailing slash and the
Directory block with the AddHandler and the trailing slash on the
dirname.

FastCgiIpcDir /tmp/fcgi_ipc FastCgiServer /usr/local/www/rails-apps/kop/current/public/dispatch.fcgi \ -initial-env RAILS_ENV=production \ -idle-timeout 60 ServerAdmin [email protected] DocumentRoot /usr/local/www/rails-apps/kop/current/public ServerName www.myhost.com ErrorLog /var/log/myhost-error_log CustomLog /var/log/myhost-access_log common Options Indexes ExecCGI FollowSymLinks RewriteEngine On ScriptAlias /cgi/ "/usr/local/www/vhosts/myhost.com/cgi/" AllowOverride all Order allow,deny Allow from all AddHandler cgi-script .cgi AddHandler fastcgi-script .fcgi

Steve K. wrote:

Have you posted the entire VirtualHost block yet? I looked through the
original thread and didn’t see it. I’m curious to see what you set your
DocumentRoot too, in particular, so maybe pasting in the whole block
will shed some light.

Also, I understand you can suexec your virtualhost as apache/apache
since it’s your machine and you can chown to it, but have you tested it
without the suexec and explicit user and group to rule that out as the
problem?

Ryan W. wrote:

Can we get a little more info? Config files, error logs, things you’ve
tried so far, etc…

Sure. Sorry. There’s another LONG thread where I went though all that
stuff which I should have referenced. But to avoid confusion (I’ve
figured out many of those issues since), I’ll start clean.

Ryan W. wrote:

Trying to access any of these results in a 404 (or
routing error if in developer mode).

Can we see the routing error?
Dan

Here is my httpd.include for that domain:

ServerName mydomain.com:80 ServerAlias www.mydomain.com UseCanonicalName Off SuexecUserGroup mydomain psacln ServerAdmin "[email protected]" DocumentRoot /home/httpd/vhosts/mydomain.com/httpdocs CustomLog /home/httpd/vhosts/mydomain.com/statistics/logs/access_log plesklog ErrorLog /home/httpd/vhosts/mydomain.com/statistics/logs/error_log UserDir /home/httpd/vhosts/mydomain.com/web_users ScriptAlias /cgi-bin/ /home/httpd/vhosts/mydomain.com/cgi-bin/ Redirect permanent /plesk-stat https://mydomain.com/plesk-stat Redirect permanent /webstat https://mydomain.com/webstat Redirect permanent /webstat-ssl https://mydomain.com/webstat-ssl Redirect permanent /ftpstat https://mydomain.com/ftpstat Redirect permanent /anon_ftpstat https://mydomain.com/anon_ftpstat SSLEngine off SetHandler perl-script PerlHandler ModPerl::Registry Options ExecCGI allow from all PerlSendHeader On php_admin_flag engine on php_admin_value open_basedir "/home/httpd/vhosts/mydomain.com/httpdocs:/tmp" php_admin_flag engine on php_admin_value open_basedir "/home/httpd/vhosts/mydomain.com/httpdocs:/tmp" SetHandler python-program PythonHandler mod_python.cgihandler Options -Includes +ExecCGI AddType text/plain .php .php4 .php3 .phtml php_admin_flag engine off AddType text/plain .php .php5 .php4 .php3 .phtml php_admin_flag engine off Alias "/error_docs" "/home/httpd/vhosts/mydomain.com/error_docs" ErrorDocument 400 /error_docs/bad_request.html ErrorDocument 401 /error_docs/unauthorized.html ErrorDocument 403 /error_docs/forbidden.html ErrorDocument 404 /error_docs/not_found.html ErrorDocument 500 /error_docs/internal_server_error.html

But, as this is all controlled by Plesk, it can not be altered.

On 4/12/06, Ryan W. [email protected] wrote:

Here is my httpd.include for that domain:

Ryan,

What’s your public/.htaccess look like?

I have Rails set up on a (Ubuntu) linux box, and had a strange
problem… I have a Rails app set up in my public_html directory in my
home directory. If I tried to access:

http://myserver/~john/test/public

I would get an error saying it could not find the file:

/home/john/public_html/test/public/index.html (which obviously was
there)

If I then tried to access

http://myserver/~john/test/public/index.html (which should be the same
thing), the default Rails “you have installed Rails” page came up!

After futzing around with Apache config files, I tried adding a
RewriteBase directive to my .htaccess file:

RewriteBase /home/john/public_html/public

and then was able to get to the file. May not be exactly what you are
seeing, but it’s something to check out.

HTH,

jt

Yes! I think you may have just solved this for me! I totally missed the
RewriteBase comment:

If your Rails application is accessed via an Alias directive,

then you MUST also set the RewriteBase in this htaccess file.

Example:

Alias /myrailsapp /path/to/myrailsapp/public

RewriteBase /myrailsapp

RewriteRule ^$ index.html [QSA]
RewriteRule ^([^.]+)$ $1.html [QSA]
RewriteCond %{REQUEST_FILENAME} !-f

BUT, I’m obviously not getting how properly do this. Everything I’ve
tried results in a 500 or 404 error directly from apache. I have my app
here behind the httpdocs web root:

/home/httpd/vhosts/mydomain.com/myapp/public

And I have a symbolic link in /home/httpd/vhosts/mydomain.com/httpdocs/
like so:

myapp -> …/myapp/public

So, I tried this:

Alias /myapp /home/httpd/vhosts/mydomain.com/myapp/public
RewriteBase /myapp

But that generated a 500 error. And trying something along the lines of
what you used:

RewriteBase /home/httpd/vhosts/mydomain.com/myapp/public

causes everyting to produce 404 errors from apache.

Suggestions?

Can we see the routing error?
Dan

Sure! This is what’s happening on my server at least. I can’t see what’s
behind the scenens at GoDaddy. From the production.log…

stylesheet:

ActionController::RoutingError (Recognition failed for
“/stylesheets/scaffold.css”):
/vendor/rails/actionpack/lib/action_controller/routing.rb:488:in
recognition_failed' /vendor/rails/actionpack/lib/action_controller/routing.rb:478:inrecognize!’
/vendor/rails/railties/lib/dispatcher.rb:38:in dispatch' /vendor/rails/railties/lib/fcgi_handler.rb:150:inprocess_request’
/vendor/rails/railties/lib/fcgi_handler.rb:54:in process!' /usr/local/lib/ruby/gems/1.8/gems/fcgi-0.8.6.1/./fcgi.rb:600:ineach_cgi’
/usr/local/lib/ruby/gems/1.8/gems/fcgi-0.8.6.1/./fcgi.rb:597:in
each_cgi' /vendor/rails/railties/lib/fcgi_handler.rb:53:inprocess!’
/vendor/rails/railties/lib/fcgi_handler.rb:23:in `process!’
dispatch.fcgi:24

javascript:

ActionController::RoutingError (Recognition failed for
“/javascripts/prototype.js”):
/vendor/rails/actionpack/lib/action_controller/routing.rb:488:in
recognition_failed' /vendor/rails/actionpack/lib/action_controller/routing.rb:478:inrecognize!’
/vendor/rails/railties/lib/dispatcher.rb:38:in dispatch' /vendor/rails/railties/lib/fcgi_handler.rb:151:inprocess_request’
/vendor/rails/railties/lib/fcgi_handler.rb:55:in process!' /usr/local/lib/ruby/gems/1.8/gems/fcgi-0.8.6.1/./fcgi.rb:600:ineach_cgi’
/usr/local/lib/ruby/gems/1.8/gems/fcgi-0.8.6.1/./fcgi.rb:597:in
each_cgi' /vendor/rails/railties/lib/fcgi_handler.rb:54:inprocess!’
/vendor/rails/railties/lib/fcgi_handler.rb:24:in `process!’
dispatch.fcgi:24

images:

ActionController::RoutingError (Recognition failed for
“/images/cog_edit.png”):
/vendor/rails/actionpack/lib/action_controller/routing.rb:488:in
recognition_failed' /vendor/rails/actionpack/lib/action_controller/routing.rb:478:inrecognize!’
/vendor/rails/railties/lib/dispatcher.rb:38:in dispatch' /vendor/rails/railties/lib/fcgi_handler.rb:151:inprocess_request’
/vendor/rails/railties/lib/fcgi_handler.rb:55:in process!' /usr/local/lib/ruby/gems/1.8/gems/fcgi-0.8.6.1/./fcgi.rb:600:ineach_cgi’
/usr/local/lib/ruby/gems/1.8/gems/fcgi-0.8.6.1/./fcgi.rb:597:in
each_cgi' /vendor/rails/railties/lib/fcgi_handler.rb:54:inprocess!’
/vendor/rails/railties/lib/fcgi_handler.rb:24:in `process!’
dispatch.fcgi:24

On 4/12/06, Ryan W. [email protected] wrote:

Yes! I think you may have just solved this for me! I totally missed the
RewriteBase comment:

causes everyting to produce 404 errors from apache.

Suggestions?

In testing, one of my trials had the Alias directive in my .htaccess
file, and it wasn’t working. Checking the Apache error.log file showed
that I couldn’t have an Alias directive in there. So I removed it. I
stuck one into the site config file -
/etc/apache2/sites-available/rails. And I also had to give Apache a
kick - apache2ctl graceful

jt

I gave up on FastCGI. Went with SCGI instead, which is GREAT! No issues
at all since.

Here’s my addition to the wiki:

http://wiki.rubyonrails.org/rails/pages/RailsWithSCGIonPlesk