danvk
danvk

Reputation: 16955

Serve compressed content XOR range: bytes with nginx

I'm serving static content using nginx. I'd like to support both Range requests and gzip compression.

Unfortunately, these two features are not compatible in nginx. Adding gzip on; to my config disables range requests.

Assuming I can't gzip everything, the next best option would be to enable gzip for all requests which lack a Range: header. Is this possible?

Upvotes: 0

Views: 595

Answers (1)

Ivan Tsirulev
Ivan Tsirulev

Reputation: 2811

The simpliest solution would be to add these lines next to every "gzip on" in your configuration:

if ($http_range) {
   gzip off;
}

Even though "if" is evil, in this case alternatives are even worse. If there are any at all.

Upvotes: 1

Related Questions