@@ -21,6 +21,7 @@ import (
2121
2222"github.com/golang/glog"
2323
24+ "fmt"
2425"k8s.io/ingress/core/pkg/ingress"
2526"k8s.io/ingress/core/pkg/ingress/defaults"
2627)
@@ -46,6 +47,10 @@ const (
4647
4748gzipTypes = "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"
4849
50+ logFormatUpstream = "'%v - [$proxy_add_x_forwarded_for] - $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'"
51+
52+ logFormatStream = "'$remote_addr [$time_local] $protocol [$ssl_preread_server_name] [$stream_upstream] $status $bytes_sent $bytes_received $session_time'"
53+
4954// http://nginx.org/en/docs/http/ngx_http_ssl_module.html#ssl_buffer_size
5055// Sets the size of the buffer used for sending data.
5156// 4k helps NGINX to improve TLS Time To First Byte (TTTFB)
@@ -143,6 +148,14 @@ type Configuration struct {
143148// Default: 4 8k
144149LargeClientHeaderBuffers string `json:"large-client-header-buffers"`
145150
151+ // Customize upstream log_format
152+ // http://nginx.org/en/docs/http/ngx_http_log_module.html#log_format
153+ LogFormatUpstream string `json:"log-format-upstream,omitempty"`
154+
155+ // Customize stream log_format
156+ // http://nginx.org/en/docs/http/ngx_http_log_module.html#log_format
157+ LogFormatStream string `json:"log-format-stream,omitempty"`
158+
146159// Maximum number of simultaneous connections that can be opened by each worker process
147160// http://nginx.org/en/docs/ngx_core_module.html#worker_connections
148161MaxWorkerConnections int `json:"max-worker-connections,omitempty"`
@@ -250,6 +263,8 @@ func NewDefault() Configuration {
250263GzipTypes : gzipTypes ,
251264KeepAlive : 75 ,
252265LargeClientHeaderBuffers : "4 8k" ,
266+ LogFormatStream : logFormatStream ,
267+ LogFormatUpstream : BuildLogFormatUpstream (false ),
253268MaxWorkerConnections : 16384 ,
254269MapHashBucketSize : 64 ,
255270ProxyRealIPCIDR : defIPCIDR ,
@@ -291,6 +306,15 @@ func NewDefault() Configuration {
291306return cfg
292307}
293308
309+ // BuildLogFormatUpstream format the log_format upstream based on proxy_protocol
310+ func BuildLogFormatUpstream (useProxyProtocol bool ) string {
311+
312+ if useProxyProtocol {
313+ return fmt .Sprintf (logFormatUpstream , "$proxy_protocol_addr" )
314+ }
315+ return fmt .Sprintf (logFormatUpstream , "$remote_addr" )
316+ }
317+
294318// TemplateConfig contains the nginx configuration to render the file nginx.conf
295319type TemplateConfig struct {
296320ProxySetHeaders map [string ]string
0 commit comments