diff --git a/src/nginxconfig/generators/conf/nginx.conf.js b/src/nginxconfig/generators/conf/nginx.conf.js index d2308b7..b0b5c33 100644 --- a/src/nginxconfig/generators/conf/nginx.conf.js +++ b/src/nginxconfig/generators/conf/nginx.conf.js @@ -73,8 +73,44 @@ export default (domains, global) => { config.http.push(['include', 'mime.types']); config.http.push(['default_type', 'application/octet-stream']); + // Append Cloudflare request headers to the default log format + if (global.logging.cloudflare.computed) { + config.http.push(['# Log Format', '']); + + // Define default log format as an array + let logging = ['$remote_addr', '-', '$remote_user', '[$time_local]', + '"$request"', '$status', '$body_bytes_sent', + '"$http_referer"', '"$http_user_agent"']; + + if (global.logging.cfRay.computed) + logging.push('$http_cf_ray'); + + if (global.logging.cfConnectingIp.computed) + logging.push('$http_cf_connecting_ip'); + + if (global.logging.xForwardedFor.computed) + logging.push('$http_x_forwarded_for'); + + if (global.logging.xForwardedProto.computed) + logging.push('$http_x_forwarded_proto'); + + if (global.logging.trueClientIp.computed) + logging.push('$http_true_client_ip'); + + if (global.logging.cfIpCountry.computed) + logging.push('$http_cf_ipcountry'); + + if (global.logging.cfVisitor.computed) + logging.push('$http_cf_visitor'); + + if (global.logging.cdnLoop.computed) + logging.push('$http_cdn_loop'); + + config.http.push(['log_format', `cloudflare '${logging.join(' ')}'`]); + } + config.http.push(['# Logging', '']); - config.http.push(['access_log', global.logging.accessLog.computed.trim() || 'off']); + 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.security.limitReq.computed) { diff --git a/src/nginxconfig/generators/conf/website.conf.js b/src/nginxconfig/generators/conf/website.conf.js index ace36e4..c4730b6 100644 --- a/src/nginxconfig/generators/conf/website.conf.js +++ b/src/nginxconfig/generators/conf/website.conf.js @@ -184,7 +184,7 @@ export default (domain, domains, global) => { serverConfig.push(['# logging', '']); if (domain.logging.accessLog.computed) - serverConfig.push(['access_log', getAccessLogDomainPath(domain, global)]); + serverConfig.push(['access_log', getAccessLogDomainPath(domain, global) + (global.logging.cloudflare.computed ? ' cloudflare' : '')]); if (domain.logging.errorLog.computed) serverConfig.push(['error_log', getErrorLogDomainPath(domain, global)]); diff --git a/src/nginxconfig/i18n/en/templates/global_sections/logging.js b/src/nginxconfig/i18n/en/templates/global_sections/logging.js index 2e33375..26e6db9 100644 --- a/src/nginxconfig/i18n/en/templates/global_sections/logging.js +++ b/src/nginxconfig/i18n/en/templates/global_sections/logging.js @@ -28,4 +28,14 @@ import common from '../../common'; export default { enableFileNotFoundErrorLogging: `${common.enable} file not found error logging in`, + logformat: 'log_format', + enableCloudflare: 'add Cloudflare request headers to the default log format', + cfRay: 'CF-Ray', + cfConnectingIp: 'CF-Connecting-IP', + xForwardedFor: 'X-Forwarded-For', + xForwardedProto: 'X-Forwarded-Proto', + trueClientIp: 'True-Client-IP', + cfIpCountry: 'CF-IPCountry', + cfVisitor: 'CF-Visitor', + cdnLoop: 'CDN-Loop', }; diff --git a/src/nginxconfig/templates/global_sections/logging.vue b/src/nginxconfig/templates/global_sections/logging.vue index 45044a4..b9a7934 100644 --- a/src/nginxconfig/templates/global_sections/logging.vue +++ b/src/nginxconfig/templates/global_sections/logging.vue @@ -77,6 +77,88 @@ THE SOFTWARE. + +
+
+ +
+
+
+
+
+ + + {{ i18n.templates.globalSections.logging.enableCloudflare }} + +
+
+
+
+ + + {{ i18n.templates.globalSections.logging.cfRay }} + +
+
+
+
+ + + {{ i18n.templates.globalSections.logging.cfConnectingIp }} + +
+
+
+
+ + + {{ i18n.templates.globalSections.logging.xForwardedFor }} + +
+
+
+
+ + + {{ i18n.templates.globalSections.logging.xForwardedProto }} + +
+
+
+
+ + + {{ i18n.templates.globalSections.logging.trueClientIp }} + +
+
+
+
+ + + {{ i18n.templates.globalSections.logging.cfIpCountry }} + +
+
+
+
+ + + {{ i18n.templates.globalSections.logging.cfVisitor }} + +
+
+
+
+ + + {{ i18n.templates.globalSections.logging.cdnLoop }} + +
+
+
+
+
@@ -99,6 +181,42 @@ THE SOFTWARE. default: false, enabled: true, }, + cloudflare: { + default: false, + enabled: true, + }, + cfRay: { + default: true, + enabled: false, + }, + cfConnectingIp: { + default: true, + enabled: false, + }, + xForwardedFor: { + default: false, + enabled: false, + }, + xForwardedProto: { + default: false, + enabled: false, + }, + trueClientIp: { + default: false, + enabled: false, + }, + cfIpCountry: { + default: false, + enabled: false, + }, + cfVisitor: { + default: false, + enabled: false, + }, + cdnLoop: { + default: false, + enabled: false, + }, }; export default { @@ -118,5 +236,48 @@ THE SOFTWARE. }; }, computed: computedFromDefaults(defaults, 'logging'), // Getters & setters for the delegated data + watch: { + // Show Cloudflare header options if Cloudflare is enabled + '$props.data.cloudflare': { + handler(data) { + if (data.computed) { + this.$props.data.cfRay.enabled = true; + this.$props.data.cfRay.computed = this.$props.data.cfRay.value; + this.$props.data.cfConnectingIp.enabled = true; + this.$props.data.cfConnectingIp.computed = this.$props.data.cfConnectingIp.value; + this.$props.data.xForwardedFor.enabled = true; + this.$props.data.xForwardedFor.computed = this.$props.data.xForwardedFor.value; + this.$props.data.xForwardedProto.enabled = true; + this.$props.data.xForwardedProto.computed = this.$props.data.xForwardedProto.value; + this.$props.data.trueClientIp.enabled = true; + this.$props.data.trueClientIp.computed = this.$props.data.trueClientIp.value; + this.$props.data.cfIpCountry.enabled = true; + this.$props.data.cfIpCountry.computed = this.$props.data.cfIpCountry.value; + this.$props.data.cfVisitor.enabled = true; + this.$props.data.cfVisitor.computed = this.$props.data.cfVisitor.value; + this.$props.data.cdnLoop.enabled = true; + this.$props.data.cdnLoop.computed = this.$props.data.cdnLoop.value; + } else { + this.$props.data.cfRay.enabled = false; + this.$props.data.cfRay.computed = false; + this.$props.data.cfConnectingIp.enabled = false; + this.$props.data.cfConnectingIp.computed = false; + this.$props.data.xForwardedFor.enabled = false; + this.$props.data.xForwardedFor.computed = false; + this.$props.data.xForwardedProto.enabled = false; + this.$props.data.xForwardedProto.computed = false; + this.$props.data.trueClientIp.enabled = false; + this.$props.data.trueClientIp.computed = false; + this.$props.data.cfIpCountry.enabled = false; + this.$props.data.cfIpCountry.computed = false; + this.$props.data.cfVisitor.enabled = false; + this.$props.data.cfVisitor.computed = false; + this.$props.data.cdnLoop.enabled = false; + this.$props.data.cdnLoop.computed = false; + } + }, + deep: true, + }, + }, };