Enable ETAG and Gzip with Nginx reverse proxy

The Problem

Although it takes just an option to enable gzip in your application. It sucks the energy out of your CPU. Thus, your best bet is Nginx.

But Nginx doesn’t have ETAG configuration for reverse proxy – it does have for static files. etag doc

This doesn’t end here – If you have Strong ETAG, it will not be passed when gzip is enabled.


Use weak ETAG instead of strong. While strong ETAG is removed from header by Nginx, weak etag is allowed to pass through.


Example uses the iris framework written in go.

app.Get("/Cache/{key:string}", func(ctx iris.Context) {
  key := ctx.Params().Get("key")
  cached, err := readFrontCache(client, key)
  eTag :=generateEtag(cached);

  // Trick is to use weak tag
  eTag = "W/\"" + eTag + "\""

  none := ctx.GetHeader("If-None-Match")

  if none == eTag {
  } else {
  ctx.Header(context.ETagHeaderKey, eTag)


Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>