Serve precompressed files without also serving their uncompressed counterparts

Hi,

Is it possible to serve precompressed files without serving their
uncompressed counterparts?

For example:
/var/www/ contains index.html.gz, but no index.html. How do I configure
nginx to respond with index.html.gz when the client supports gzip or let
nginx decompress the file on the fly when the client does not support
gzip?

Based on this answer on stackoverflow gzip - nginx gzip_static: why are the non-compressed files required? - Server Fault, I
am
currently using the following configuration:

location / {
try_files $uri $uri/ @application;
root /var/www;
gzip_static on;
gunzip on;
}

@application configures the application server.
When I try get the index.html page, nginx return a 403 forbidden error.

Posted at Nginx Forum:

On Tuesday 22 December 2015 11:01:19 snieuwen wrote:

Based on this answer on stackoverflow gzip - nginx gzip_static: why are the non-compressed files required? - Server Fault, I am
When I try get the index.html page, nginx return a 403 forbidden error.

[…]

gzip_static always;

See the documentation: Module ngx_http_gzip_static_module

wbr, Valentin V. Bartenev

On Tuesday 22 December 2015 19:05:18 Valentin V. Bartenev wrote:

@application configures the application server.
When I try get the index.html page, nginx return a 403 forbidden error.

[…]

gzip_static always;

See the documentation: Module ngx_http_gzip_static_module

[…]

But your problem is caused by “try_files”, since you have configured
it to check “$uri” and “$uri/” instead of “$uri.gz”.

The configuration below should work for you:

location / {
root /var/www;

   gzip_static always;
   gunzip on;

   error_page 404 = @application;

}

wbr, Valentin V. Bartenev

Hello!

On Tue, Dec 22, 2015 at 07:15:53PM +0300, Valentin V. Bartenev wrote:

nginx decompress the file on the fly when the client does not support gzip?

   error_page 404 = @application;

}

Likely 403 is returned because there is no index file
(Module ngx_http_index_module), and the request is to “/”, not to
“/index.html”. I don’t think there is a good solution.


Maxim D.
http://nginx.org/