From 8e2d5436f7c21e88f6a3f98015f4b8ccd97f1288 Mon Sep 17 00:00:00 2001 From: Kobi Meirson Date: Mon, 17 Oct 2022 15:03:24 +0300 Subject: [PATCH] chore: per-domain logging --- src/nginxconfig/generators/conf/nginx.conf.js | 15 +++++- .../generators/conf/website.conf.js | 8 +-- .../templates/domain_sections/logging.vue | 4 +- .../templates/global_sections/logging.vue | 54 +++++++++++++++++-- src/nginxconfig/util/get_log_paths.js | 4 +- 5 files changed, 70 insertions(+), 15 deletions(-) diff --git a/src/nginxconfig/generators/conf/nginx.conf.js b/src/nginxconfig/generators/conf/nginx.conf.js index e2feb5f..d99586c 100644 --- a/src/nginxconfig/generators/conf/nginx.conf.js +++ b/src/nginxconfig/generators/conf/nginx.conf.js @@ -107,8 +107,19 @@ export default (domains, global) => { } config.http.push(['# Logging', '']); - config.http.push(['access_log', (global.logging.accessLog.computed.trim() + (global.logging.cloudflare.computed ? ' cloudflare' : '')) || 'off']); - config.http.push(['error_log', global.logging.errorLog.computed.trim() || '/dev/null']); + if (global.logging.accessLog.computed) { + config.http.push(['access_log', global.logging.accessLogPath.computed.trim() + + (global.logging.cloudflare.computed ? ' cloudflare' : '') + + (global.logging.accessLogArguments.computed ? ` ${global.logging.accessLogArguments.computed.trim()}` : '') + ]); + } else { + config.http.push(['access_log', 'off']); + } + if (global.logging.errorLog.computed) { + config.http.push(['error_log', global.logging.errorLogPath.computed.trim()]); + } else { + config.http.push(['error_log', '/dev/null']); + } if (global.security.limitReq.computed) { config.http.push(['# Limits', '']); diff --git a/src/nginxconfig/generators/conf/website.conf.js b/src/nginxconfig/generators/conf/website.conf.js index 0363f5d..63e432b 100644 --- a/src/nginxconfig/generators/conf/website.conf.js +++ b/src/nginxconfig/generators/conf/website.conf.js @@ -226,7 +226,10 @@ export default (domain, domains, global, ipPortPairs) => { if (domain.logging.accessLog.computed) serverConfig.push(['access_log', - getAccessLogDomainPath(domain, global) + (global.logging.cloudflare.computed ? ' cloudflare' : '')]); + getAccessLogDomainPath(domain, global) + + (global.logging.cloudflare.computed ? ' cloudflare' : '') + + (global.logging.accessLogArguments.computed ? ` ${global.logging.accessLogArguments.computed.trim()}`: '') + ]); if (domain.logging.errorLog.computed) serverConfig.push(['error_log', getErrorLogDomainPath(domain, global)]); @@ -369,9 +372,6 @@ export default (domain, domains, global, ipPortPairs) => { // HTTPS cdnConfig.push(...sslConfig(domain, global)); - cdnConfig.push(['# disable access_log', '']); - cdnConfig.push(['access_log', 'off']); - // Gzip if (global.performance.gzipCompression.computed) { cdnConfig.push(['# gzip', '']); diff --git a/src/nginxconfig/templates/domain_sections/logging.vue b/src/nginxconfig/templates/domain_sections/logging.vue index 3335a0e..39969ef 100644 --- a/src/nginxconfig/templates/domain_sections/logging.vue +++ b/src/nginxconfig/templates/domain_sections/logging.vue @@ -69,11 +69,11 @@ THE SOFTWARE. const defaults = { accessLog: { - default: false, + default: true, enabled: true, }, errorLog: { - default: false, + default: true, enabled: true, }, }; diff --git a/src/nginxconfig/templates/global_sections/logging.vue b/src/nginxconfig/templates/global_sections/logging.vue index c831a3b..9b36917 100644 --- a/src/nginxconfig/templates/global_sections/logging.vue +++ b/src/nginxconfig/templates/global_sections/logging.vue @@ -33,11 +33,36 @@ THE SOFTWARE.
+
+ + {{ $t('common.enable') }} + +
+
+
+
+
+
+ + +
+
+ +
+
+
+
+
@@ -51,11 +76,18 @@ THE SOFTWARE.
+
+ + {{ $t('common.enable') }} + +
+
+
@@ -161,10 +193,22 @@ THE SOFTWARE. const defaults = { accessLog: { + default: false, + enabled: true, + }, + accessLogPath: { default: '/var/log/nginx/access.log', enabled: true, }, + accessLogArguments: { + default: 'buffer=512k flush=1m', + enabled: true, + }, errorLog: { + default: false, + enabled: true, + }, + errorLogPath: { default: '/var/log/nginx/error.log warn', enabled: true, }, @@ -263,7 +307,7 @@ THE SOFTWARE. } }, deep: true, - }, + } }, }; diff --git a/src/nginxconfig/util/get_log_paths.js b/src/nginxconfig/util/get_log_paths.js index d61db2c..03f4bd8 100644 --- a/src/nginxconfig/util/get_log_paths.js +++ b/src/nginxconfig/util/get_log_paths.js @@ -25,9 +25,9 @@ THE SOFTWARE. */ export const getAccessLogDomainPath = (domain, global) => { - return global.logging.accessLog.computed.replace(/([^/]+)\.log$/, `${domain.server.domain.computed}.$1.log`); + return global.logging.accessLogPath.computed.replace(/([^/]+)\.log$/, `${domain.server.domain.computed}.$1.log`); }; export const getErrorLogDomainPath = (domain, global) => { - return global.logging.errorLog.computed.replace(/([^/]+)\.log (.+)$/, `${domain.server.domain.computed}.$1.log $2`); + return global.logging.errorLogPath.computed.replace(/([^/]+)\.log (.+)$/, `${domain.server.domain.computed}.$1.log $2`); };