Nginx Content-Length Header for Static Files with Gzip – How to Force

gzipnginxstatic-content

We're running Nginx 0.7.65[-1ubuntu2.3]. I've just noticed that when serving local static files using an alias directive and gzip on, the Content-Length header is not getting sent. Since it's serving files from the local filesystem, it shouldn't have any problem getting the length. How can I force Nginx to send a Content-Length header with these files?

Best Answer

It turns out that when using dynamic Gzip then the Content-Length header is not sent, as the Transfer-Encoding is chunked. Pre-compressing my files and switching to static Gzip allows Nginx to know ahead of time the file size and send an appropriate Content-Length header.