Repository: digitalocean/nginxconfig.io
File: src/nginxconfig/generators/conf/nginx.conf.js (JavaScript)

Code before:
                ips.push('9.9.9.9', '149.112.112.112');
            if (['ipv6', 'both'].includes(global.https.ocspQuad9Type.computed))
                ips.push('[2620:fe::fe]', '[2620:fe::9]');
        }
        if (global.https.ocspVerisign.computed) {
            if (['ipv4', 'both'].includes(global.https.ocspVerisignType.computed))
                ips.push('64.6.64.6', '64.6.65.6');
            if (['ipv6', 'both'].includes(global.https.ocspVerisignType.computed))
                ips.push('[2620:74:1b::1:1]', '[2620:74:1c::2:2]');
        }

        if (ips.length) {
            config.http.push(['resolver', `${ips.join(' ')} valid=60s`]);
            config.http.push(['resolver_timeout', '2s']);
        }
    }

    // Connection header for WebSocket reverse proxy
    if (domains.some(d => d.reverseProxy.reverseProxy.computed)) {
        config.http.push(['# Connection header for WebSocket reverse proxy', '']);
        config.http.push(['map $http_upgrade $connection_upgrade', {
            'default': 'upgrade',
            '""': 'close',
        }]);
        config.http.push(['map $remote_addr $proxy_forwarded_elem', {
            '~^[0-9.]+$': '"for=$remote_addr"',
            '~^[0-9A-Fa-f:.]+$': '"for=\\"[$remote_addr]\\""',
            'default': '"for=unknown"',
        }]);
        config.http.push(['map $http_forwarded $proxy_add_forwarded', {
            '': '"~^(,[ \\\\t]*)*([!#$%&\'*+.^_`|~0-9A-Za-z-]+=([!#$%&\'*+.^_`|~0-9A-Za-z-]+|\\"([\\\\t \\\\x21\\\\x23-\\\\x5B\\\\x5D-\\\\x7E\\\\x80-\\\\xFF]|\\\\\\\\[\\\\t \\\\x21-\\\\x7E\\\\x80-\\\\xFF])*\\"))?(;([!#$%&\'*+.^_`|~0-9A-Za-z-]+=([!#$%&\'*+.^_`|~0-9A-Za-z-]+|\\"([\\\\t \\\\x21\\\\x23-\\\\x5B\\\\x5D-\\\\x7E\\\\x80-\\\\xFF]|\\\\\\\\[\\\\t \\\\x21-\\\\x7E\\\\x80-\\\\xFF])*\\"))?)*([ \\\\t]*,([ \\\\t]*([!#$%&\'*+.^_`|~0-9A-Za-z-]+=([!#$%&\'*+.^_`|~0-9A-Za-z-]+|\\"([\\\\t \\\\x21\\\\x23-\\\\x5B\\\\x5D-\\\\x7E\\\\x80-\\\\xFF]|\\\\\\\\[\\\\t \\\\x21-\\\\x7E\\\\x80-\\\\xFF])*\\"))?(;([!#$%&\'*+.^_`|~0-9A-Za-z-]+=([!#$%&\'*+.^_`|~0-9A-Za-z-]+|\\"([\\\\t \\\\x21\\\\x23-\\\\x5B\\\\x5D-\\\\x7E\\\\x80-\\\\xFF]|\\\\\\\\[\\\\t \\\\x21-\\\\x7E\\\\x80-\\\\xFF])*\\"))?)*)?)*$" "$http_forwarded, $proxy_forwarded_elem"',
            'default': '"$proxy_forwarded_elem"',
        }]);
    }

    // Configs!
    config.http.push(['# Load configs', '']);
    config.http.push(['include', [
        `${global.nginx.nginxConfigDirectory.computed.replace(/\/+$/, '')}/conf.d/*.conf`,
        global.tools.modularizedStructure.computed ? `${global.nginx.nginxConfigDirectory.computed.replace(/\/+$/, '')}/sites-enabled/*` : '',
    ].filter(x => x.length)]);

    // Single file configs
    if (!global.tools.modularizedStructure.computed) {
        for (const domain of domains) {
            config.http.push([`# ${domain.server.domain.computed}`, '']);
            config.http.push(...websiteConf(domain, domains, global));
        }
    }

    // Done!

Review comment (suggestion):
```suggestion
        // See https://www.nginx.com/resources/wiki/start/topics/examples/forwarded/
        config.http.push(['# Forwarded header coexisting with X-Forwarded-*', '']);
        config.http.push(['map $remote_addr $proxy_forwarded_elem', {
```
Add a note in the config itself about what the maps are for, and a comment in the JS as a ref for future contributors :)

Code after:
                ips.push('9.9.9.9', '149.112.112.112');
            if (['ipv6', 'both'].includes(global.https.ocspQuad9Type.computed))
                ips.push('[2620:fe::fe]', '[2620:fe::9]');
        }
        if (global.https.ocspVerisign.computed) {
            if (['ipv4', 'both'].includes(global.https.ocspVerisignType.computed))
                ips.push('64.6.64.6', '64.6.65.6');
            if (['ipv6', 'both'].includes(global.https.ocspVerisignType.computed))
                ips.push('[2620:74:1b::1:1]', '[2620:74:1c::2:2]');
        }

        if (ips.length) {
            config.http.push(['resolver', `${ips.join(' ')} valid=60s`]);
            config.http.push(['resolver_timeout', '2s']);
        }
    }

    // Connection header for WebSocket reverse proxy
    if (domains.some(d => d.reverseProxy.reverseProxy.computed)) {
        config.http.push(['# Connection header for WebSocket reverse proxy', '']);
        config.http.push(['map $http_upgrade $connection_upgrade', {
            'default': 'upgrade',
            '""': 'close',
        }]);
        // See https://www.nginx.com/resources/wiki/start/topics/examples/forwarded/
        config.http.push(['map $remote_addr $proxy_forwarded_elem', {
            '# IPv4 addresses can be sent as-is': '',
            '~^[0-9.]+$': '"for=$remote_addr"',
            '# IPv6 addresses need to be bracketed and quoted': '',
            '~^[0-9A-Fa-f:.]+$': '"for=\\"[$remote_addr]\\""',
            '# Unix domain socket names cannot be represented in RFC 7239 syntax': '',
            'default': '"for=unknown"',
        }]);
        config.http.push(['map $http_forwarded $proxy_add_forwarded', {
            '# If the incoming Forwarded header is syntactically valid, append to it': '',
            '': '"~^(,[ \\\\t]*)*([!#$%&\'*+.^_`|~0-9A-Za-z-]+=([!#$%&\'*+.^_`|~0-9A-Za-z-]+|\\"([\\\\t \\\\x21\\\\x23-\\\\x5B\\\\x5D-\\\\x7E\\\\x80-\\\\xFF]|\\\\\\\\[\\\\t \\\\x21-\\\\x7E\\\\x80-\\\\xFF])*\\"))?(;([!#$%&\'*+.^_`|~0-9A-Za-z-]+=([!#$%&\'*+.^_`|~0-9A-Za-z-]+|\\"([\\\\t \\\\x21\\\\x23-\\\\x5B\\\\x5D-\\\\x7E\\\\x80-\\\\xFF]|\\\\\\\\[\\\\t \\\\x21-\\\\x7E\\\\x80-\\\\xFF])*\\"))?)*([ \\\\t]*,([ \\\\t]*([!#$%&\'*+.^_`|~0-9A-Za-z-]+=([!#$%&\'*+.^_`|~0-9A-Za-z-]+|\\"([\\\\t \\\\x21\\\\x23-\\\\x5B\\\\x5D-\\\\x7E\\\\x80-\\\\xFF]|\\\\\\\\[\\\\t \\\\x21-\\\\x7E\\\\x80-\\\\xFF])*\\"))?(;([!#$%&\'*+.^_`|~0-9A-Za-z-]+=([!#$%&\'*+.^_`|~0-9A-Za-z-]+|\\"([\\\\t \\\\x21\\\\x23-\\\\x5B\\\\x5D-\\\\x7E\\\\x80-\\\\xFF]|\\\\\\\\[\\\\t \\\\x21-\\\\x7E\\\\x80-\\\\xFF])*\\"))?)*)?)*$" "$http_forwarded, $proxy_forwarded_elem"',
            '# Otherwise, replace it': '',
            'default': '"$proxy_forwarded_elem"',
        }]);
    }

    // Configs!
    config.http.push(['# Load configs', '']);
    config.http.push(['include', [
        `${global.nginx.nginxConfigDirectory.computed.replace(/\/+$/, '')}/conf.d/*.conf`,
        global.tools.modularizedStructure.computed ? `${global.nginx.nginxConfigDirectory.computed.replace(/\/+$/, '')}/sites-enabled/*` : '',
    ].filter(x => x.length)]);

    // Single file configs
    if (!global.tools.modularizedStructure.computed) {
        for (const domain of domains) {