diff options
Diffstat (limited to 'nixos/helpers.nix')
-rw-r--r-- | nixos/helpers.nix | 42 |
1 files changed, 41 insertions, 1 deletions
diff --git a/nixos/helpers.nix b/nixos/helpers.nix index 0588cd6..e7e1877 100644 --- a/nixos/helpers.nix +++ b/nixos/helpers.nix @@ -3,10 +3,50 @@ let in { mkNginxConfig = name: '' - access_log /var/log/nginx/${name}.access.log; + access_log /var/log/nginx/${name}.access.log json; error_log /var/log/nginx/${name}.error.log; ''; + commonHttpConfig = '' + map $request_uri $request_uri_path { + "~^(?P<path>[^?]*)(\?.*)?$" $path; + } + log_format json escape=json '{' + '"msec": "$msec", ' # request unixtime in seconds with a milliseconds resolution + '"remote_addr": "$remote_addr", ' # client IP + '"remote_user": "$remote_user", ' # client HTTP username + '"method": "$request_method", ' + '"path": "$request_uri_path", ' + '"args": "$args", ' + '"status": "$status", ' # response status code + '"user_agent": "$http_user_agent", ' + '"body_bytes_sent": "$body_bytes_sent", ' # the number of body bytes exclude headers sent to a client + '"request_time": "$request_time", ' # request processing time in seconds with msec resolution + '"http_host": "$http_host", ' # the request Host: header + '"http_referer": "$http_referer", ' # HTTP referer + '"http_x_forwarded_for": "$http_x_forwarded_for", ' # http_x_forwarded_for + '"connection": "$connection", ' # connection serial number + '"connection_requests": "$connection_requests", ' # number of requests made in connection + '"request_id": "$request_id", ' # the unique request id + '"request_length": "$request_length", ' # request length (including headers and body) + '"time_iso8601": "$time_iso8601", ' # local time in the ISO 8601 standard format + '"bytes_sent": "$bytes_sent", ' # the number of bytes sent to a client + '"server_name": "$server_name", ' # the name of the vhost serving the request + '"upstream": "$upstream_addr", ' # upstream backend server for proxied requests + '"upstream_connect_time": "$upstream_connect_time", ' # upstream handshake time incl. TLS + '"upstream_header_time": "$upstream_header_time", ' # time spent receiving upstream headers + '"upstream_response_time": "$upstream_response_time", ' # time spend receiving upstream body + '"upstream_response_length": "$upstream_response_length", ' # upstream response length + '"upstream_cache_status": "$upstream_cache_status", ' # cache HIT/MISS where applicable + '"ssl_protocol": "$ssl_protocol", ' # TLS protocol + '"ssl_cipher": "$ssl_cipher", ' # TLS cipher + '"scheme": "$scheme", ' # http or https + '"server_protocol": "$server_protocol", ' # request protocol, like HTTP/1.1 or HTTP/2.0 + '"pipe": "$pipe", ' # "p" if request was pipelined, "." otherwise + '"gzip_ratio": "$gzip_ratio"' + '}'; + ''; + joinWgNamespace = ns: cfg: nixpkgs.lib.attrsets.recursiveUpdate cfg { bindsTo = ["netns@${ns}.service"]; |