From 96e72a44bb60516943c7c8aca3241c9f5ca7aeb1 Mon Sep 17 00:00:00 2001 From: MattIPv4 Date: Fri, 15 May 2020 20:31:54 +0100 Subject: [PATCH] Some more confs --- src/nginxconfig/generators/website.conf.js | 36 +++++++++++++++++++++- src/nginxconfig/util/get_log_paths.js | 7 +++++ 2 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 src/nginxconfig/util/get_log_paths.js diff --git a/src/nginxconfig/generators/website.conf.js b/src/nginxconfig/generators/website.conf.js index dac3aa9..e1951bc 100644 --- a/src/nginxconfig/generators/website.conf.js +++ b/src/nginxconfig/generators/website.conf.js @@ -1,6 +1,7 @@ import { getSslCertificate, getSslCertificateKey } from '../util/get_ssl_certificate'; import commonHsts from '../util/common_hsts'; import securityConf from './security.conf'; +import { getAccessLogDomainPath, getErrorLogDomainPath } from '../util/get_log_paths'; export default (domain, domains, global) => { // Use kv so we can use the same key multiple times @@ -77,7 +78,40 @@ export default (domain, domains, global) => { } // Access log or error log for domain - // TODO: this & beyond + if (domain.logging.accessLog.computed || domain.logging.errorLog.computed) { + serverConfig.push(['# logging', '']); + + if (domain.logging.accessLog.computed) + serverConfig.push(['access_log', getAccessLogDomainPath(domain, global)]); + + if (domain.logging.errorLog.computed) + serverConfig.push(['error_log', getErrorLogDomainPath(domain, global)]); + } + + // index.php + if (domain.routing.index.computed === 'index.php') { + serverConfig.push(['# index.php', '']); + serverConfig.push(['index', 'index.php']); + } + + // Fallback index.html or index.php + if ((domain.routing.fallbackHtml.computed || domain.routing.fallbackPhp.computed) + && (!domain.reverseProxy.reverseProxy.computed || domain.reverseProxy.path.computed !== '/')) { + serverConfig.push([`# index.${domain.routing.fallbackHtml.computed ? 'html' : (domain.routing.fallbackPhp.computed ? 'php' : '' )} fallback`, '']); + serverConfig.push(['location /', { + try_files: `$uri $uri/ /index.${domain.routing.fallbackHtml.computed ? '.html' : (domain.routing.fallbackPhp.computed ? '.php?$query_string' : '')}`, + }]); + } + + // Fallback index.html and index.php + if (domain.routing.fallbackHtml.computed && domain.routing.fallbackPhp.computed) { + serverConfig.push(['# index.php fallback', '']); + serverConfig.push([`location ~ ^${domain.routing.fallbackPhpPath.computed}`, { + try_files: '$uri $uri/ /index.php?$query_string', + }]); + } + + // TODO: Python onwards // Add the server config to the parent config now its built config.push(['server', serverConfig]); diff --git a/src/nginxconfig/util/get_log_paths.js b/src/nginxconfig/util/get_log_paths.js new file mode 100644 index 0000000..fb9dc7b --- /dev/null +++ b/src/nginxconfig/util/get_log_paths.js @@ -0,0 +1,7 @@ +export const getAccessLogDomainPath = (domain, global) => { + return global.logging.accessLog.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`); +};