Not signed in (Sign In)
    • CommentAuthordgrant
    • CommentTimeJan 20th 2009
     permalink
    I'm trying to serve up static media from a /site_media URL. Inside my server {} block of my nginx conf I have this:

    location /site_media {
    root <someLocalPathThatDoesExist>;
    }
    if (-f $request_filename) {
    break;
    }

    But when I go to http://recipes.davidgrant.ca/site_media/css/recipes.css for example, I get a 404 error.

    Any ideas on what I might be missing?
    • CommentAuthormeppum
    • CommentTimeJan 20th 2009
     permalink
    make sure that your location and root values have a trailing '/':

    location /site_media/ {
    root /somepath/;
    }
    •  
      CommentAuthornezroy
    • CommentTimeJan 20th 2009 edited
     permalink
    Make sure that <someLocalPathThatDoesExist> has a site_media subdirectory. If your file system is "/var/lib/www/site_media/" then your config should look like this:

    location /site_media/ {
    root /var/lib/www/;
    }

    The "root" directive specifies the root of the entire URI, not just the portion that was left over after the location match. If you want that, you need to use "alias" instead:

    location /path_I_want_to_point_at_site_media/ {
    alias /var/lib/www/site_media/;
    }

    Or even the following, which is functionally equivalent to the first one using "root", though less efficient:

    location /site_media/ {
    alias /var/lib/www/site_media/;
    }
    • CommentAuthordgrant
    • CommentTimeJan 20th 2009
     permalink
    Thanks so much. I'm pretty sure that these tips will work and I'll try them tonight and hopefully they will.

    nezroy, I think you're right, I probably meant to use alias here, instead I used root. My path on the filesystem does not have a site_media folder in it, so I'll change my root (thanks for mentioning that alias is less efficient, I wasn't aware of that).
    •  
      CommentAuthornezroy
    • CommentTimeJan 20th 2009
     permalink
    (thanks for mentioning that alias is less efficient, I wasn't aware of that).


    Well, don't put too much stock in that :) The difference is negligible as far as I can tell, and I wouldn't avoid using alias just for that if it's right for the setup you want. The real handiness of root vs alias is that you can put root in a server or http block and have its value inherited by all the interior location blocks, which is somewhat more convenient to manage from a config point of view in certain setups. alias can only be used inside a location block, and has some restrictions when doing regex location matches.