0

Is there any way to enable GZIP / Brotli compression on Cloudfront if the origin is a nginx server with SSI (Server Side Includes) enabled?

The issue seems that nginx SSI drops the Content-Length header, as it doesn’t know the content length at the time of sending the headers as the file hasn’t been parsed. However, Cloudfront apparently requires the Content-Length header to compress the request:

The response must include a Content-Length header so CloudFront can determine whether the size of the file is in the range that CloudFront compresses. If the Content-Length header is missing, CloudFront won’t compress the file.

Cloudfront Documentation

Is there any way to enforce nginx to parse the whole file (and apply the SSI) before sending the headers and therefore including the Content-Length as well? Or even better: Force Cloudfront to compress subsequent cache hits for which it obviously already knows the content length?

rauberdaniel
  • 141
  • 5
  • Can't you get rid of the SSI? SSI is 1990s era stuff and I'm surprised Igor ever put it into nginx at all. The web moved on and it's mostly forgotten today. – Michael Hampton Jun 02 '21 at 12:30
  • I doubt that AWS would implement complex logic like compressing subsequent cache hits. You can try to file a feature request for them. I also doubt that nginx would have something like you seek, because it complicates the request processing flow for little benefit. You would need to add some other component to do the SSI before nginx processes the request. – Tero Kilkanen Jun 02 '21 at 15:12

0 Answers0