nginx configuration

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.

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.

dhis2 (1.15 KB)

I think this is a good and simple starting point. The only issue I see for this is another situation, where mutliple DHIS2 instances are running on the same machine, but under a different virtual host. This is simple enough with the “server_name” directive, so we might need to at least document this. Not exactly sure how common this is, but might be good to include it anyway.

Regards,

Jason

···

On Thu, Mar 28, 2013 at 7:15 PM, Bob Jolliffe bobjolliffe@gmail.com 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)

  1. I’ve done the proxy pass configs as one-liners which should make

easy for scriptable editing with sed

  1. 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.

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.


Mailing list: https://launchpad.net/~dhis2-devs

Post to : dhis2-devs@lists.launchpad.net

Unsubscribe : https://launchpad.net/~dhis2-devs

More help : https://help.launchpad.net/ListHelp

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
Apache Tomcat 7 Configuration Reference (7.0.109) - Container Provided Filters)
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.

···

On 28 March 2013 17:15, Bob Jolliffe <bobjolliffe@gmail.com> wrote:

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.

I think this is a good and simple starting point. The only issue I see for
this is another situation, where mutliple DHIS2 instances are running on the
same machine, but under a different virtual host. This is simple enough with
the "server_name" directive, so we might need to at least document this. Not
exactly sure how common this is, but might be good to include it anyway.

Yes I can see this would be a different way of "fronting". I am going
to concentrate on one approach for now where the webapp is mapped into
the url of a single host, but maybe we could consider scripting the
virtualhost setup as well in the future.

···

On 29 March 2013 15:16, Jason Pickering <jason.p.pickering@gmail.com> wrote:

Regards,
Jason

On Thu, Mar 28, 2013 at 7:15 PM, Bob Jolliffe <bobjolliffe@gmail.com> 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.

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.

_______________________________________________
Mailing list: DHIS 2 developers in Launchpad
Post to : dhis2-devs@lists.launchpad.net
Unsubscribe : DHIS 2 developers in Launchpad
More help : ListHelp - Launchpad Help

Hi Bob,

thanks for working on this. The config looks good.

Have you confirmed that chrome and firefox will do (expiry) caching of static content without validating with the server over SSL?

Morten, I seem to recall that the smartphone mobile module needs to know the protocol on SSL to function properly, is that right? If so we need:

proxy_set_header X-Forwarded-Proto https;

regards,

Lars

···

On Fri, Mar 29, 2013 at 5:27 PM, Bob Jolliffe bobjolliffe@gmail.com wrote:

On 29 March 2013 15:16, Jason Pickering jason.p.pickering@gmail.com wrote:

I think this is a good and simple starting point. The only issue I see for

this is another situation, where mutliple DHIS2 instances are running on the

same machine, but under a different virtual host. This is simple enough with

the “server_name” directive, so we might need to at least document this. Not

exactly sure how common this is, but might be good to include it anyway.

Yes I can see this would be a different way of “fronting”. I am going

to concentrate on one approach for now where the webapp is mapped into

the url of a single host, but maybe we could consider scripting the

virtualhost setup as well in the future.

Regards,

Jason

On Thu, Mar 28, 2013 at 7:15 PM, Bob Jolliffe bobjolliffe@gmail.com 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)

  1. I’ve done the proxy pass configs as one-liners which should make

easy for scriptable editing with sed

  1. 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.

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.


Mailing list: https://launchpad.net/~dhis2-devs

Post to : dhis2-devs@lists.launchpad.net

Unsubscribe : https://launchpad.net/~dhis2-devs

More help : https://help.launchpad.net/ListHelp


Mailing list: https://launchpad.net/~dhis2-devs

Post to : dhis2-devs@lists.launchpad.net

Unsubscribe : https://launchpad.net/~dhis2-devs

More help : https://help.launchpad.net/ListHelp