Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Serve static assets and media separately from meteor with nginx?

Coming from Django I'm accustomed to serving my static assets and media (including uploads) separately from the main wsgi or other app. This flat file structure is easy to navigate and manage.

I can't seem to find any examples of how to do this (serve static assets/media separately) with Meteor.

  1. Is there a standard approach?

  2. Are there packages that provide this functionality?

My end goals are:

  1. to be able to more intuitively navigate all the static assets and media and access them from a publicly accessible URL without having to hot rebuild the meteor app. The "public" folder doesn't do it for me... especially for uploaded media.

  2. upload to this system path (which is separate from the main meteor app) either manually when migrating an app or via a custom app/package I write.

  3. browse/parse the path from meteor app/package

like image 518
rjmoggach Avatar asked Oct 01 '15 05:10

rjmoggach


2 Answers

If you would want this for performance and scalability reasons (see my comment) you should go with a Caching Proxy. Initially the proxy will fetch a static file from the Meteor app directly, but subsequent requests will be served from its cache.

This article (nginx-caching) is a good read about how to set-up a caching proxy with Nginx in general. Also, Meteorpedia has an article explaining how to setup an Nginx cache specifically tailored for a Meteor app.

like image 77
Jeroen Peeters Avatar answered Sep 19 '22 16:09

Jeroen Peeters


If all your static assets have a common path, for instance /static/..., then you can tell nginx to alias requests to that path with a directory

location /static  {
    alias /path/to/static/assets;
}
like image 38
elssar Avatar answered Sep 19 '22 16:09

elssar