Forbidden error for static files (javascripts, images, etc.)

3104 views
Skip to first unread message

Jared White

unread,
Apr 12, 2008, 2:53:18 AM4/12/08
to Phusion Passenger Discussions
I installed Passenger on my Ubuntu box with a custom-built Apache
2.2.6, and all of the Rails side of the app works great, but static
files are not being loaded. I get a standard 403 Forbidden error
served by Apache, and in my error_log file, all I get is

client denied by server configuration: /myxyzappfolder/public/
javascripts/effects.js

etc. My app appears to have been spawned by my regular user account on
the box and all my app files are owned by me, not to mention they're
at least readable by everyone. I had renamed .htaccess to
htaccess.dumb just in case mod_rewrite was messing something up, but
that didn't help.

Any ideas or tips on how to troubleshoot further? It seems like this
should be a no-brainer, but I can't figure it out.

Jared

tamerhel...@gmail.com

unread,
Apr 12, 2008, 3:19:21 AM4/12/08
to Phusion Passenger Discussions
"Static assets are accelerated, i.e. they are served directly by
Apache and do not go through the Rails stack".

I think this is straight an Apache error.

Google gave valid answers - http://www.google.ca/search?q=+client+denied+by+server+configuration

hello...@gmail.com

unread,
Apr 12, 2008, 9:06:02 AM4/12/08
to Phusion Passenger Discussions
I had the same issue, try something like this:

<VirtualHost *:80>
ServerName selleo.com
ServerAlias www.selleo.com
DocumentRoot /var/www/selleo.com/public
<Directory "/var/www/selleo.com/public">
Options FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
RailsBaseURI /
</VirtualHost>

Cheers,
Tomasz Bak

Jared White

unread,
Apr 12, 2008, 11:37:28 AM4/12/08
to Phusion Passenger Discussions
Ah, that makes sense. Thanks Tomasz, it works great now. I think the
docs should make note of this, considering that not everyone is going
to realize that they need to have a standard working setup in the
Apache config for accessing their static files BEFORE they even think
about putting in the Rails component. I thought that would happen
automatically.

Thanks again,

Jared

On Apr 12, 6:06 am, "helloli...@gmail.com" <helloli...@gmail.com>
wrote:

ChrisR

unread,
Apr 12, 2008, 2:48:41 PM4/12/08
to Phusion Passenger Discussions
Thanks Tomasz, it might have taken me a while to figure out this
obvious solution.

I agree with you Jared, the docs should make note of it.

Thanks
Chris


Hongli Lai

unread,
Apr 13, 2008, 7:23:39 AM4/13/08
to phusion-...@googlegroups.com

Thanks for the feedback. I've updated the users guide accordingly.

--
Phusion | The Computer Science Company

Web: http://www.phusion.nl/
E-mail: in...@phusion.nl
Chamber of commerce no: 08173483 (The Netherlands)

Kivanio

unread,
Apr 13, 2008, 9:24:48 AM4/13/08
to Phusion Passenger Discussions
Hi,

i have problem with css, js and images.

i put the confs:

<VirtualHost *:
80>
ServerName www.proalmat.facual.org.br
DocumentRoot /home/www/ruby/proalmatfacual/
public

<Directory "/home/www/ruby/proalmatfacual/
public">
Options
FollowSymLinks
AllowOverride
None
Order
allow,deny
Allow from
all
</
Directory>

RailsBaseURI /
</VirtualHost>

but don't works for me, see logs:

ActionController::RoutingError (No route matches "/stylesheets/
defaults.css" with {:method=>:get}):
/vendor/rails/actionpack/lib/action_controller/routing.rb:1441:in
`recognize_path'
/vendor/rails/actionpack/lib/action_controller/routing.rb:1424:in
`recognize'
/vendor/rails/actionpack/lib/action_controller/dispatcher.rb:
170:in `handle_request'
/vendor/rails/actionpack/lib/action_controller/dispatcher.rb:
115:in `dispatch'
/vendor/rails/actionpack/lib/action_controller/dispatcher.rb:
126:in `dispatch_cgi
ActionController::RoutingError (No route matches "/images/
menu_oproalmat.jpg" with {:method=>:get}):
/vendor/rails/actionpack/lib/action_controller/routing.rb:1441:in
`recognize_path'
/vendor/rails/actionpack/lib/action_controller/routing.rb:1424:in
`recognize'
/vendor/rails/actionpack/lib/action_controller/dispatcher.rb:
170:in `handle_request'
/vendor/rails/actionpack/lib/action_controller/dispatcher.rb:
115:in `dispatch'
/vendor/rails/actionpack/lib/action_controller/dispatcher.rb:
126:in `dispatch_cgi'
/vendor/rails/actionpack/lib/action_controller/dispatcher.rb:9:in
`dispatch'

httpd log:

[0x3368:StandardApplicationPool.h:0xf9] Cleaning idle app /home/www/
ruby/proalmatfacual (PID 0x33e8)
[0x3368:Application.h:0x112] Application 0x847cb00: destroyed.
[0x33cc:Hooks.cpp:0x172] Processing HTTP request: /
[0x3368:ApplicationPoolClientServer.h:0x1aa] Client 0x842a600:
received message: ['get', '/home/www/ruby/proalmatfacual', 'true',
'nobody']
[0x3368:Application.h:0x108] Application 0x847c860: created.
[0x3368:ApplicationPoolClientServer.h:0x1aa] Client 0x842a600:
received message: ['close', '13']
[13255:Hooks.cpp:370] Processing HTTP request: /images/menu_home.jpg
[0x3368:ApplicationPoolClientServer.h:0x1aa] Client 0x842a600:
received message: ['get', '/home/www/ruby/proalmatfacual', 'true',
'nobody']
[0x3368:ApplicationPoolClientServer.h:0x1aa] Client 0x842a600:
received message: ['close', '11']
[13254:Hooks.cpp:370] Processing HTTP request: /images/
menu_oproalmat.jpg
[0x3368:ApplicationPoolClientServer.h:0x1aa] Client 0x842a600:
received message: ['get', '/home/www/ruby/proalmatfacual', 'true',
'nobody']
[0x3368:ApplicationPoolClientServer.h:0x1aa] Client 0x842a600:
received message: ['close', '11']
[13253:Hooks.cpp:370] Processing HTTP request: /stylesheets/
defaults.css
[0x3368:ApplicationPoolClientServer.h:0x1aa] Client 0x842a600:
received message: ['get', '/home/www/ruby/proalmatfacual', 'true',
'nobody']
[0x3368:ApplicationPoolClientServer.h:0x1aa] Client 0x842a600:
received message: ['close', '4']
[0x33cd:Hooks.cpp:0x172] Processing HTTP request: /images/
transparente.gif
[0x3368:ApplicationPoolClientServer.h:0x1aa] Client 0x842a600:
received message: ['get', '/home/www/ruby/proalmatfacual', 'true',
'nobody']
[0x3368:ApplicationPoolClientServer.h:0x1aa] Client 0x842a600:
received message: ['close', '3']


i have other 3 app rails runing just with:

<VirtualHost *:
80>
ServerName
estoque.facual.org.br
DocumentRoot /home/www/ruby/intranetfacual/
public
</VirtualHost>

and i don't have problem, just the app above don't work.


PS: sorry for my bad english, i'm from brazil and i'm learning :)


On 13 abr, 07:23, Hongli Lai <hon...@phusion.nl> wrote:
> ChrisR wrote:
> > Thanks Tomasz, it might have taken me a while to figure out this
> > obvious solution.
>
> > I agree with you Jared, the docs should make note of it.
>
> > Thanks
> > Chris
>
> Thanks for the feedback. I've updated the users guide accordingly.
>
> --
> Phusion | The Computer Science Company
>
> Web:http://www.phusion.nl/
> E-mail: i...@phusion.nl

Kivanio Barbosa

unread,
Apr 13, 2008, 9:06:16 PM4/13/08
to Phusion Passenger Discussions
Hi,

i solve my problem.

in my case, the problem was permissions.

in app with error, the permissions was 700, the rails work, but images don't.

i change to 755, after 754, after 754, and 750.

all works fine now.
--
Kivanio Pereira Barbosa
Cel 8121-4248

www.eiqconsultoria.com.br

allenlux

unread,
May 3, 2008, 6:37:19 AM5/3/08
to Phusion Passenger Discussions
I've followed all the guidance on this, but I still can't see the
images in my Rails application.

My virtual host looks like this:

<VirtualHost *>
ServerAdmin john@kirtley

DocumentRoot /home/usr/HomePage/Current/

<Directory "/home/usr/HomePage/Current/">
Options FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>

<Directory "/home/usr/jallen/ruby/Depot2/public">
Options FollowSymLinks
Order allow,deny
Allow from all
</Directory>

RailsBaseURI /app1
RailsEnv development

</VirtualHost>


The Depot2 application (this is the sample application from the book
"Agile Web Development with Rails") lives at /home/usr/jallen/ruby/
Depot2

This folder and everything inside it has permissions 777 and belongs
to a general-purpose user "pcguest".

The DocumentRoot is "/home/usr/HomePage/Current" and within this
folder there is a symbolic link "app1" which points to /home/usr/
jallen/ruby/Depot2/public.

In the Apache error log, I'm seeing messages like:
[Sat May 03 12:17:18 2008] [error] [client 192.168.0.1] File does not
exist: /home/usr/HomePage/Current/images, referer: http://allenlux.dyndns.org/app1

which seems to indicate that the Rails application is looking for the
images in "/home/usr/HomePage/Current/images" which of course doesn't
exist. It should be looking in "/home/usr/jallen/ruby/Depot2/public/
images".

Everything else in the Depot2 application works fine.

Is this a bug in the application, or a problem with my Apache
configuration?

--
John Allen




Hongli Lai

unread,
May 8, 2008, 3:51:01 AM5/8/08
to phusion-...@googlegroups.com
allenlux wrote:
> which seems to indicate that the Rails application is looking for the
> images in "/home/usr/HomePage/Current/images" which of course doesn't
> exist. It should be looking in "/home/usr/jallen/ruby/Depot2/public/
> images".

Maybe your HTML is referencing /images/foo.png instead of
/app1/images/foo.png?

--
Phusion | The Computer Science Company

Web: http://www.phusion.nl/
E-mail: in...@phusion.nl

allenlux

unread,
May 9, 2008, 9:04:33 AM5/9/08
to Phusion Passenger Discussions
On May 8, 9:51 am, Hongli Lai <hon...@phusion.nl> wrote:
> allenlux wrote:
> > which seems to indicate that the Rails application is looking for the
> > images in "/home/usr/HomePage/Current/images" which of course doesn't
> > exist. It should be looking in "/home/usr/jallen/ruby/Depot2/public/
> > images".
>
> Maybe your HTML is referencing /images/foo.png instead of
> /app1/images/foo.png?

Thanks, you are right. I changed the paths in the Depot2 application
and now the images are visible.

But now I have 2 more questions:

1. The Depot2 application worked fine with the original image
references when running under webrick or mongrel. It seems curious
that running under Passenger requires that all the image references
have to be changed.

2. The path "/app1/images/foo.png" seems counter-intuitive to me. The
application folder is Depot2, so why isn't the path "/Depot2/images/
foo.png"? I thought that "app1" was just a way for Passenger to find
its way from the Apache virtual host to the real folder for the Rails
application.

John Allen

Hongli Lai

unread,
May 9, 2008, 10:00:46 AM5/9/08
to phusion-...@googlegroups.com
allenlux wrote:
> 1. The Depot2 application worked fine with the original image
> references when running under webrick or mongrel. It seems curious
> that running under Passenger requires that all the image references
> have to be changed.

Back when it was running in Mongrel, was Depot2 deployed to a subdirectory?

Passenger doesn't, and can't, fix the HTML output for you - you have to
do that yourself.


> 2. The path "/app1/images/foo.png" seems counter-intuitive to me. The
> application folder is Depot2, so why isn't the path "/Depot2/images/
> foo.png"? I thought that "app1" was just a way for Passenger to find
> its way from the Apache virtual host to the real folder for the Rails
> application.

Because "app1" is part of the URI while "Depot2" is part of the
filename. Since this is HTTP, you're supposed to reference everything by
URI. The actual on-disk filename has got nothing to do with it.

allenlux

unread,
May 9, 2008, 2:01:56 PM5/9/08
to Phusion Passenger Discussions
On May 9, 4:00 pm, Hongli Lai <hon...@phusion.nl> wrote:
> allenlux wrote:
> > 1. The Depot2 application worked fine with the original image
> > references when running under webrick or mongrel. It seems curious
> > that running under Passenger requires that all the image references
> > have to be changed.
>
> Back when it was running in Mongrel, was Depot2 deployed to a subdirectory?
>
I just copied the demo application into the directory:
//kirtley/home/usr/jallen/ruby/Depot2

Underneath this directory are all the usual Rails folders: app/,
components/, public/, script etc.

With Depot2 as my current working directory, I can start the
application under Mongrel with the command script/server.

I then can access the application via the URLs:
http://kirtley:3000 (local only)
http://allenlux.dyndns.org:3000

This still works, although after changing the image paths for
Passenger the images can't be found by the instance of Depot2 running
under Mongrel.


> Passenger doesn't, and can't, fix the HTML output for you - you have to
> do that yourself.
>
> > 2. The path "/app1/images/foo.png" seems counter-intuitive to me. The
> > application folder is Depot2, so why isn't the path "/Depot2/images/
> > foo.png"? I thought that "app1" was just a way for Passenger to find
> > its way from the Apache virtual host to the real folder for the Rails
> > application.
>
> Because "app1" is part of the URI while "Depot2" is part of the
> filename. Since this is HTTP, you're supposed to reference everything by
> URI. The actual on-disk filename has got nothing to do with it.

In theory, yes, but I still find it puzzling that 2 different servers
for Rails apparently handle these URIs differently.

John Allen

Hongli Lai

unread,
May 9, 2008, 2:54:19 PM5/9/08
to phusion-...@googlegroups.com
allenlux wrote:
> In theory, yes, but I still find it puzzling that 2 different servers
> for Rails apparently handle these URIs differently.

I don't understand what you're expecting. It's your *HTML* that's
referencing the wrong URIs. Passenger or the web server have got nothing
to do with it.

allenlux

unread,
May 9, 2008, 4:52:08 PM5/9/08
to Phusion Passenger Discussions
On May 9, 8:54 pm, Hongli Lai <hon...@phusion.nl> wrote:
> allenlux wrote:
> > In theory, yes, but I still find it puzzling that 2 different servers
> > for Rails apparently handle these URIs differently.
>
> I don't understand what you're expecting. It's your *HTML* that's
> referencing the wrong URIs. Passenger or the web server have got nothing
> to do with it.

I did a little more research which I should have done before, of
course.

This Rails wiki article seems to make it clearer, at least for me:
http://wiki.rubyonrails.com/rails/pages/HowToLinkToStaticFile

It does make the point
"When running under Webrick, files under the public directory can be
accessed using an absolute URL, as in

<img src="/images/someimage.gif"/>"

but that this doesn't work for any server where the application is not
at the document root. In these cases it suggests

<%= image_tag "someimage.gif" %>

as a general solution for image files.

See also this thread:
http://groups.google.com/group/comp.lang.ruby/browse_thread/thread/ea964464f871d048

which was the origin of the wiki article.

Please tell me if you think the wiki is giving bad advice on this
issue.

John
Reply all
Reply to author
Forward
0 new messages