crossplane: Add brotli and proxy_hide_header (#11678)
Signed-off-by: Gabriel M. Dutra <me@dutralabs.xyz>
This commit is contained in:
parent
796621ccaf
commit
52e66af219
4 changed files with 35 additions and 11 deletions
|
@ -34,5 +34,13 @@ func (c *Template) buildConfig() {
|
||||||
if c.tplConfig.Cfg.WorkerCPUAffinity != "" {
|
if c.tplConfig.Cfg.WorkerCPUAffinity != "" {
|
||||||
config.Parsed = append(config.Parsed, buildDirective("worker_cpu_affinity", c.tplConfig.Cfg.WorkerCPUAffinity))
|
config.Parsed = append(config.Parsed, buildDirective("worker_cpu_affinity", c.tplConfig.Cfg.WorkerCPUAffinity))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if c.tplConfig.Cfg.EnableBrotli {
|
||||||
|
config.Parsed = append(config.Parsed,
|
||||||
|
buildDirective("load_module", "/etc/nginx/modules/ngx_http_brotli_filter_module.so"),
|
||||||
|
buildDirective("load_module", "/etc/nginx/modules/ngx_http_brotli_static_module.so"),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
c.config = config
|
c.config = config
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,6 +68,7 @@ func TestCrossplaneTemplate(t *testing.T) {
|
||||||
Cfg: config.NewDefault(),
|
Cfg: config.NewDefault(),
|
||||||
}
|
}
|
||||||
tplConfig.Cfg.DefaultSSLCertificate = defaultCertificate
|
tplConfig.Cfg.DefaultSSLCertificate = defaultCertificate
|
||||||
|
tplConfig.Cfg.EnableBrotli = true
|
||||||
|
|
||||||
tpl := crossplane.NewTemplate()
|
tpl := crossplane.NewTemplate()
|
||||||
tpl.SetMimeFile(mimeFile.Name())
|
tpl.SetMimeFile(mimeFile.Name())
|
||||||
|
|
|
@ -233,6 +233,21 @@ func (c *Template) buildHTTP() {
|
||||||
httpBlock = append(httpBlock, buildDirective("proxy_pass_header", "Server"))
|
httpBlock = append(httpBlock, buildDirective("proxy_pass_header", "Server"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if cfg.EnableBrotli {
|
||||||
|
httpBlock = append(httpBlock,
|
||||||
|
buildDirective("brotli", "on"),
|
||||||
|
buildDirective("brotli_comp_level", cfg.BrotliLevel),
|
||||||
|
buildDirective("brotli_min_length", cfg.BrotliMinLength),
|
||||||
|
buildDirective("brotli_types", cfg.BrotliTypes),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(cfg.HideHeaders) > 0 {
|
||||||
|
for k := range cfg.HideHeaders {
|
||||||
|
httpBlock = append(httpBlock, buildDirective("proxy_hide_header", cfg.HideHeaders[k]))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
c.config.Parsed = append(c.config.Parsed, &ngx_crossplane.Directive{
|
c.config.Parsed = append(c.config.Parsed, &ngx_crossplane.Directive{
|
||||||
Directive: "http",
|
Directive: "http",
|
||||||
Block: httpBlock,
|
Block: httpBlock,
|
||||||
|
|
|
@ -346,10 +346,6 @@ http {
|
||||||
proxy_intercept_errors on;
|
proxy_intercept_errors on;
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
||||||
# END MIGRATED VARIOUS 1
|
|
||||||
|
|
||||||
{{ buildOpentelemetry $cfg $servers }}
|
|
||||||
|
|
||||||
{{ if $cfg.EnableBrotli }}
|
{{ if $cfg.EnableBrotli }}
|
||||||
brotli on;
|
brotli on;
|
||||||
brotli_comp_level {{ $cfg.BrotliLevel }};
|
brotli_comp_level {{ $cfg.BrotliLevel }};
|
||||||
|
@ -357,6 +353,17 @@ http {
|
||||||
brotli_types {{ $cfg.BrotliTypes }};
|
brotli_types {{ $cfg.BrotliTypes }};
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
||||||
|
{{ if $cfg.AllowBackendServerHeader }}
|
||||||
|
proxy_pass_header Server;
|
||||||
|
{{ end }}
|
||||||
|
|
||||||
|
{{ range $header := $cfg.HideHeaders }}proxy_hide_header {{ $header }};
|
||||||
|
{{ end }}
|
||||||
|
|
||||||
|
# END MIGRATED VARIOUS 1
|
||||||
|
|
||||||
|
{{ buildOpentelemetry $cfg $servers }}
|
||||||
|
|
||||||
# Create a variable that contains the literal $ character.
|
# Create a variable that contains the literal $ character.
|
||||||
# This works because the geo module will not resolve variables.
|
# This works because the geo module will not resolve variables.
|
||||||
geo $literal_dollar {
|
geo $literal_dollar {
|
||||||
|
@ -366,13 +373,6 @@ http {
|
||||||
{{ range $errCode := $cfg.CustomHTTPErrors }}
|
{{ range $errCode := $cfg.CustomHTTPErrors }}
|
||||||
error_page {{ $errCode }} = @custom_upstream-default-backend_{{ $errCode }};{{ end }}
|
error_page {{ $errCode }} = @custom_upstream-default-backend_{{ $errCode }};{{ end }}
|
||||||
|
|
||||||
{{ if $cfg.AllowBackendServerHeader }}
|
|
||||||
proxy_pass_header Server;
|
|
||||||
{{ end }}
|
|
||||||
|
|
||||||
{{ range $header := $cfg.HideHeaders }}proxy_hide_header {{ $header }};
|
|
||||||
{{ end }}
|
|
||||||
|
|
||||||
upstream upstream_balancer {
|
upstream upstream_balancer {
|
||||||
server 0.0.0.1; # placeholder
|
server 0.0.0.1; # placeholder
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue