From da8165ec732f7c692b21ef15f537f2801ab12f47 Mon Sep 17 00:00:00 2001 From: Ricardo Pchevuzinske Katz Date: Wed, 1 Nov 2017 16:43:57 -0200 Subject: [PATCH] Adds Brotli support --- pkg/nginx/config/config.go | 15 +++++++++++++++ rootfs/etc/nginx/template/nginx.tmpl | 7 +++++++ 2 files changed, 22 insertions(+) diff --git a/pkg/nginx/config/config.go b/pkg/nginx/config/config.go index cd24170c9..083eaf3b9 100644 --- a/pkg/nginx/config/config.go +++ b/pkg/nginx/config/config.go @@ -47,6 +47,8 @@ const ( gzipTypes = "application/atom+xml application/javascript application/x-javascript application/json application/rss+xml application/vnd.ms-fontobject application/x-font-ttf application/x-web-app-manifest+json application/xhtml+xml application/xml font/opentype image/svg+xml image/x-icon text/css text/plain text/x-component" + brotliTypes = "application/xml+rss application/atom+xml application/javascript application/x-javascript application/json application/rss+xml application/vnd.ms-fontobject application/x-font-ttf application/x-web-app-manifest+json application/xhtml+xml application/xml font/opentype image/svg+xml image/x-icon text/css text/plain text/x-component" + logFormatUpstream = `%v - [$the_real_ip] - $remote_user [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent" $request_length $request_time [$proxy_upstream_name] $upstream_addr $upstream_response_length $upstream_response_time $upstream_status` logFormatStream = `[$time_local] $protocol $status $bytes_sent $bytes_received $session_time` @@ -331,6 +333,16 @@ type Configuration struct { // http://nginx.org/en/docs/http/ngx_http_gzip_module.html UseGzip bool `json:"use-gzip,omitempty"` + // Enables or disables the use of the NGINX Brotli Module for compression + // https://github.com/google/ngx_brotli + UseBrotli bool `json:"use-brotli,omitempty"` + + // Brotli Compression Level that will be used + BrotliLevel int `json:"brotli-level,omitempty"` + + // MIME Types that will be compressed on-the-fly using Brotli module + BrotliTypes string `json:"brotli-types,omitempty"` + // Enables or disables the HTTP/2 support in secure connections // http://nginx.org/en/docs/http/ngx_http_v2_module.html // Default: true @@ -424,6 +436,8 @@ func NewDefault() Configuration { AllowBackendServerHeader: false, AccessLogPath: "/var/log/nginx/access.log", ErrorLogPath: "/var/log/nginx/error.log", + BrotliLevel: 4, + BrotliTypes: brotliTypes, ClientHeaderBufferSize: "1k", ClientHeaderTimeout: 60, ClientBodyBufferSize: "8k", @@ -462,6 +476,7 @@ func NewDefault() Configuration { SSLSessionCacheSize: sslSessionCacheSize, SSLSessionTickets: true, SSLSessionTimeout: sslSessionTimeout, + UseBrotli: true, UseGzip: true, WorkerProcesses: strconv.Itoa(runtime.NumCPU()), WorkerShutdownTimeout: "10s", diff --git a/rootfs/etc/nginx/template/nginx.tmpl b/rootfs/etc/nginx/template/nginx.tmpl index 99dece999..98076681d 100644 --- a/rootfs/etc/nginx/template/nginx.tmpl +++ b/rootfs/etc/nginx/template/nginx.tmpl @@ -112,6 +112,13 @@ http { include /etc/nginx/mime.types; default_type text/html; + + {{ if $cfg.UseBrotli }} + brotli on; + brotli_comp_level {{ $cfg.BrotliLevel }}; + brotli_types {{ $cfg.BrotliTypes }}; + {{ end }} + {{ if $cfg.UseGzip }} gzip on; gzip_comp_level 5;