Static file serving only works if root is a subfolder under public

lulalala nginx-forum at
Fri Jul 6 03:50:18 UTC 2012

I am trying to serve static cache files using nginx. There are
index.html files under the rails_root/public/cache directory. I tried
the following configuration first, which doesn't work:

    root <%= current_path %>/public;
    try_files /cache$uri/index.html /cache$uri.html @rails;

Accessing the root / gives this error:

    [error] 4056#0: *13503414 directory index of "(...)current/public/"
is forbidden, request: "GET / HTTP/1.1"

I then tried 

    root <%= current_path %>/public/cache;
    try_files $uri/index.html $uri.html @rails;

And to my surprise this works.


The permissions of the folders are:

    775 public
      755 cache
        644 index.html

The thing is that my favicon sitting under public/ is served correctly:

    # asset server
    server {
      listen 80;
      server_name assets.<%= server_name %>;
      expires max;
      add_header Cache-Control public;
      charset utf-8;
      root   <%= current_path %>/public;

So, why is it that I can do the latter not the former( since they point
to the same location)? Thanks.

Posted at Nginx Forum:,228318,228318#msg-228318

More information about the nginx mailing list