← Back to team overview

dhis2-devs team mailing list archive

Re: nginx configuration

 

On 28 March 2013 17:15, Bob Jolliffe <bobjolliffe@xxxxxxxxx> wrote:
> I've run a few experiments with nginx and caching, verified with tcpdump.
>
> Attached is my suggestion for an nginx conf file dealing with multiple
> tomcat backends.
>
> A few things to note:
> 1.  this is not a full nginx.conf, but rather /etc/nginx/conf.d/dhis2
> as you would find when installing nginx from deb (which I am going to
> recommend)
> 2.  I've done the proxy pass configs as one-liners which should make
> easy for scriptable editing with sed
> 3.  after lots of fiddling with the static content business I have
> just dropped it for now.  What I have found and confirmed (at least
> with chrome) is that chrome is caching this content anyway so there is
> only very marginal utility in getting it served by nginx directly from
> the file system.  It will only be required occasionally.  The nginx
> cache doesn't work quite like the apache one in that this stuff is not
> automatically being cached by the proxy.  If it did then this would
> far and away be the simplest way to get served directly off the
> filesystem.  I guess in order to make this happen we have to set the
> Cache-Control headers with interceptors from within the webapp.  Which
> I think this is the right way to go about it anyway.  Using the proxy
> to fiddle with cache-control headers feels wrong.   Either way,
> because of the browser caching behaviour its actually a pretty small
> optimisation so I'm happy to lose it for now.

I added ExpiresFilter to tomcat's web.xml file (like
http://tomcat.apache.org/tomcat-7.0-doc/config/filter.html#Expires_Filter)
and now all my static content is getting cached by nginx.  Which is
cool because nginx will now serve that stuff with fast sendfile
without me having to tell it about the document root of the webapp.

Given that I am providing tomcat's configuration with a skeleton
(similar to tomcat7-user) then I can just set this as the default on
install and forget about it.  Just need to to do some fine tuning of
the regex on the url-pattern.

>
> Any comments on the conf file?
>
> Bob
>
> PS.  contrary to popular opinion I think the apache config is actually
> much more straightforward, but for the moment it looks like nginx is
> clearly superior on memory usage which I think is our primary concern
> in most cases.


References