Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem open_file_cache directive and brotli_static on #105

Open
kvakanet opened this issue Jul 24, 2020 · 0 comments
Open

Problem open_file_cache directive and brotli_static on #105

kvakanet opened this issue Jul 24, 2020 · 0 comments

Comments

@kvakanet
Copy link

Hello!

  1. Created precompressed files .br
  2. Set in nginx
brotli_static on;
open_file_cache max=2048 inactive=20s;
  1. Sent request:
    curl https://example.ru/bitrix/js/ui/bootstrap4/css/bootstrap.min.css -I -A curl-Bortli -H 'Accept-Encoding: br'
    and got response
server: nginx
date: Fri, 24 Jul 2020 06:16:29 GMT
content-type: text/css
content-length: 140936
last-modified: Wed, 22 Jul 2020 12:07:04 GMT
etag: "5f182be8-22688"
expires: Fri, 31 Jul 2020 06:16:29 GMT
cache-control: max-age=604800
accept-ranges: bytes

but if you check response several times:

server: nginx
date: Fri, 24 Jul 2020 06:19:37 GMT
content-type: text/css
content-length: 15812
last-modified: Wed, 22 Jul 2020 12:07:04 GMT
etag: "5f182be8-3dc4"
content-encoding: br
expires: Fri, 31 Jul 2020 06:19:37 GMT
cache-control: max-age=604800

and so with a probability of 50%

  1. If enable in nginx gzip_static on and create precompressed files .gz and send request
    curl https://example.ru/bitrix/js/ui/bootstrap4/css/bootstrap.min.css -I -A curl-Gzip -H 'Accept-Encoding: gzip'
  2. Then get response
server: nginx
date: Fri, 24 Jul 2020 06:22:53 GMT
content-type: text/css
content-length: 20942
last-modified: Fri, 24 Jul 2020 03:17:35 GMT
etag: "5f1a52cf-51ce"
content-encoding: gzip
expires: Fri, 31 Jul 2020 06:22:53 GMT
cache-control: max-age=604800

100% every time.

  1. If remove from nginx open_file_cache max=2048 inactive=20s;
    And send request
    curl https://example.ru/bitrix/js/ui/bootstrap4/css/bootstrap.min.css -I -A curl-Bortli -H 'Accept-Encoding: br'
    Then Response:
HTTP/2 200 
server: nginx
date: Fri, 24 Jul 2020 06:28:43 GMT
content-type: text/css
content-length: 15812
last-modified: Wed, 22 Jul 2020 12:07:04 GMT
etag: "5f182be8-3dc4"
content-encoding: br
expires: Fri, 31 Jul 2020 06:28:43 GMT
cache-control: max-age=604800

100% every time

  1. Ok. I created patch
diff -ruN orig/static/ngx_http_brotli_static_module.c my/static/ngx_http_brotli_static_module.c                                                                                                                    
--- orig/static/ngx_http_brotli_static_module.c 2020-04-23 13:55:31.000000000 +0300                                                                                                                                
+++ my/static/ngx_http_brotli_static_module.c   2020-07-23 18:37:00.978000000 +0300                                                                                                                                
@@ -178,7 +178,9 @@                                                                                                                                                                                                
   if (last == NULL) return NGX_HTTP_INTERNAL_SERVER_ERROR;                                                                                                                                                        
   /* +1 for reinstating the terminating 0. */                                                                                                                                                                     
   ngx_cpystrn(last, kSuffix, kSuffixLen + 1);                                                                                                                                                                     
-  path.len += kSuffixLen;                                                                                                                                                                                         
+  /* Kuka Patch for work with open_file_cache like gzip_static */                                                                                                                                               
+  path.len = last - path.data;                                                                                                                                                                                    
+                                                                                                                                                                                                                  
                                                                                                                                                                                                                   
   log = req->connection->log;                                                                                                                                                                                     
   ngx_log_debug1(NGX_LOG_DEBUG_HTTP, log, 0, "http filename: \"%s\"",                                                                                                                                             

compile dynamic module and check again with settings nginx open_file_cache max=2048 inactive=20s;
Sent request:
curl https://example.ru/bitrix/js/ui/bootstrap4/css/bootstrap.min.css?1595419624140936 -I -A curl-Bortli -H 'Accept-Encoding: br'
Then response:

HTTP/2 200 
server: nginx
date: Fri, 24 Jul 2020 06:34:50 GMT
content-type: text/css
content-length: 15812
last-modified: Wed, 22 Jul 2020 12:07:04 GMT
etag: "5f182be8-3dc4"
content-encoding: br
expires: Fri, 31 Jul 2020 06:34:50 GMT
cache-control: max-age=604800

100% every time like gzip_static
8. But there is the problem with my patch. If I add open_file_cache_errors on; setting to nginx and request html page with many resources
then sometimes I got 404 error for resources (.png).
If I set open_file_cache_errors off; the everything works fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant