0

I can't set up nginx 1.18 (Ubuntu 22.04 as a server env, Chrome 104 as a client) for dealing with .br or .gz files.

My frontend code bundler (Parcel 2) has generated .br and .gz index.html files but when I'm trying to access https://mysite/index.html it throws 404 Not found, and with https://mysite/index.html.br it's just trying to download Brotli file.

My assumption is that Nginx should send .br or .gz file to Chrome and Chrome should automatically extract it to regular html-file and display web page. Is it right or not?

This is an extract from my nginx.conf:

load_module modules/ngx_http_brotli_filter_module.so;
load_module modules/ngx_http_brotli_static_module.so;
...
...
...
       ##
        # Gzip Settings
        ##

        gzip on;

        # gzip_vary on;
        # gzip_proxied any;
        # gzip_comp_level 6;
        # gzip_buffers 16 8k;
        # gzip_http_version 1.1;
        # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

        brotli on;
        brotli_static on;
        brotli_types
        text/plain
        text/css
        text/xml
        text/javascript
        text/x-component
        application/xml
        application/xml+rss
        application/javascript
        application/json
        application/atom+xml
        application/vnd.ms-fontobject
        application/x-font-ttf
        application/x-font-opentype
        application/x-font-truetype
        application/x-web-app-manifest+json
        application/xhtml+xml
        application/octet-stream
        font/opentype
        font/truetype
        font/eot
        font/otf
        image/svg+xml
        image/x-icon
        image/vnd.microsoft.icon
        image/bmp;

This is server conf:

...
    location ~* \.(js|jpg|png|jpg|jpeg|git|ico|css|eot|woff|woff2|svg|webmanifest)$ {
      root /var/www/main;
      try_files $uri $uri/ /webgl$uri =404;
    }

    location / {
      root /var/www/main/webgl;
      try_files $uri $uri/ =404;
    }
...

What I have to do? Thank you!

Eddie R
  • 101
  • 2

2 Answers2

0

If you don't have the uncompressed version on your server, you need to use nginx gunzip module to make nginx uncompress the file when client requests the uncompressed version of the file.

gzip_static only tells nginx to send the .gz version to clients who tell they accept gzip encoded responses.

Tero Kilkanen
  • 36,796
  • 3
  • 41
  • 63
  • Thank you Tero! I see that Chrome initiates request *with* support of br and gz formats: "accept-encoding: gzip, deflate, br". But I'm still getting error like "403 Forbidden" due to nginx can't browse root directory because it's impossible to find index.html (just index.html.br and index.html.gz exist) – Eddie R Aug 21 '22 at 19:30
0

It seems like Nginx can't handle index.html.br and index.html.gz without having index.html version in folder.

Solution: Just add files without compression to your folder and Nginx will send compressed files (of course if browser will send proper accept-encoding attribute in request (e.g. accept-encoding: gzip, deflate, br).

Ref https://trac.nginx.org/nginx/ticket/1367

Eddie R
  • 101
  • 2