Skip to content

Commit 9f83100

Browse files
authored
Merge pull request #255 from rikatz/nginx-disable-access-log
Adds support for disabling access_log globally
2 parents 2119b23 + d0c4e0d commit 9f83100

File tree

4 files changed

+19
-0
lines changed

4 files changed

+19
-0
lines changed

controllers/nginx/configuration.md

+3
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,9 @@ Setting at least one code also enables [proxy_intercept_errors](http://nginx.org
188188
Example usage: `custom-http-errors: 404,415`
189189

190190

191+
**disable-access-log:** Disables the Access Log from the entire Ingress Controller. This is 'false' by default.
192+
193+
191194
**enable-dynamic-tls-records:** Enables dynamically sized TLS records to improve time-to-first-byte. Enabled by default. See [CloudFlare's blog](https://blog.cloudflare.com/optimizing-tls-over-tcp-to-reduce-latency) for more information.
192195

193196

controllers/nginx/pkg/config/config.go

+5
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ type Configuration struct {
8888
// http://nginx.org/en/docs/http/ngx_http_core_module.html#client_header_buffer_size
8989
ClientHeaderBufferSize string `json:"client-header-buffer-size"`
9090

91+
// DisableAccessLog disables the Access Log globally from NGINX ingress controller
92+
//http://nginx.org/en/docs/http/ngx_http_log_module.html
93+
DisableAccessLog bool `json:"disable-access-log,omitempty"`
94+
9195
// EnableSPDY enables spdy and use ALPN and NPN to advertise the availability of the two protocols
9296
// https://blog.cloudflare.com/open-sourcing-our-nginx-http-2-spdy-code
9397
// By default this is enabled
@@ -233,6 +237,7 @@ type Configuration struct {
233237
func NewDefault() Configuration {
234238
cfg := Configuration{
235239
ClientHeaderBufferSize: "1k",
240+
DisableAccessLog: false,
236241
EnableDynamicTLSRecords: true,
237242
EnableSPDY: false,
238243
ErrorLogLevel: errorLevel,

controllers/nginx/pkg/template/configmap_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,14 @@ func TestMergeConfigMapToStruct(t *testing.T) {
3939
"proxy-send-timeout": "2",
4040
"skip-access-log-urls": "/log,/demo,/test",
4141
"use-proxy-protocol": "true",
42+
"disable-access-log": "true",
4243
"use-gzip": "true",
4344
"enable-dynamic-tls-records": "false",
4445
"gzip-types": "text/html",
4546
}
4647
def := config.NewDefault()
4748
def.CustomHTTPErrors = []int{300, 400}
49+
def.DisableAccessLog = true
4850
def.SkipAccessLogURLs = []string{"/log", "/demo", "/test"}
4951
def.ProxyReadTimeout = 1
5052
def.ProxySendTimeout = 2

controllers/nginx/rootfs/etc/nginx/template/nginx.tmpl

+9
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,11 @@ http {
8787
default 1;
8888
}
8989

90+
{{ if $cfg.DisableAccessLog }}
91+
access_log off;
92+
{{ else }}
9093
access_log /var/log/nginx/access.log upstreaminfo if=$loggable;
94+
{{ end }}
9195
error_log /var/log/nginx/error.log {{ $cfg.ErrorLogLevel }};
9296

9397
{{ buildResolvers $cfg.Resolver }}
@@ -424,7 +428,12 @@ stream {
424428

425429
log_format log_stream '$remote_addr [$time_local] $protocol [$ssl_preread_server_name] [$stream_upstream] $status $bytes_sent $bytes_received $session_time';
426430

431+
{{ if $cfg.DisableAccessLog }}
432+
access_log off;
433+
{{ else }}
427434
access_log /var/log/nginx/access.log log_stream;
435+
{{ end }}
436+
428437
error_log /var/log/nginx/error.log;
429438

430439
# configure default backend for SSL

0 commit comments

Comments
 (0)