# Serve precompressed files without also serving their uncompressed counterparts

**URL:** <https://www.ruby-forum.com/t/serve-precompressed-files-without-also-serving-their-uncompressed-counterparts/243698>\
**Category:** NGINX\
**Created:** [December 22, 2015, 5:01pm UTC](https://www.ruby-forum.com/t/serve-precompressed-files-without-also-serving-their-uncompressed-counterparts/243698 "2015-12-22T17:01:56Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rafa\_F](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/958977/32.png) [@Rafa\_F](https://www.ruby-forum.com/u/Rafa_F)\
**Post date:** [December 22, 2015, 5:01pm UTC](https://www.ruby-forum.com/t/serve-precompressed-files-without-also-serving-their-uncompressed-counterparts/243698/1 "2015-12-22T17:01:56Z")

</div>

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](http://serverfault.com/a/611757), 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:

> **[serve precompressed files without also serving their uncompressed counterparts](https://forum.nginx.org/read.php?2,263641,263641#msg-263641)**
>
> 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...

---

<div class="post-metadata">

**Author:** ![snieuwen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/bcef8e/32.png) [@snieuwen](https://www.ruby-forum.com/u/snieuwen)\
**Post date:** [December 22, 2015, 5:06pm UTC](https://www.ruby-forum.com/t/serve-precompressed-files-without-also-serving-their-uncompressed-counterparts/243698/2 "2015-12-22T17:06:01Z")

</div>

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

> Based on this answer on stackoverflow [http://serverfault.com/a/611757](http://serverfault.com/a/611757), 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](http://nginx.org/r/gzip_static)

wbr, Valentin V. Bartenev

---

<div class="post-metadata">

**Author:** ![snieuwen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/bcef8e/32.png) [@snieuwen](https://www.ruby-forum.com/u/snieuwen)\
**Post date:** [December 22, 2015, 5:16pm UTC](https://www.ruby-forum.com/t/serve-precompressed-files-without-also-serving-their-uncompressed-counterparts/243698/3 "2015-12-22T17:16:32Z")

</div>

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](http://nginx.org/r/gzip_static)

[..]

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

---

<div class="post-metadata">

**Author:** ![snieuwen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/bcef8e/32.png) [@snieuwen](https://www.ruby-forum.com/u/snieuwen)\
**Post date:** [December 22, 2015, 5:24pm UTC](https://www.ruby-forum.com/t/serve-precompressed-files-without-also-serving-their-uncompressed-counterparts/243698/4 "2015-12-22T17:24:43Z")

</div>

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](http://nginx.org/r/index)), and the request is to “/”, not to  
“/index.html”. I don’t think there is a good solution.

–  
Maxim D.

> **[nginx](http://nginx.org/)**
