nginx-builder
v0.1.0
Published
![Heading](https://www.f5.com/content/dam/f5-com/page-assets-en/home-en/products/nginx/2020/nginx-product-icon-open-source_1100x481.jpg)
Downloads
83
Readme
Simple Nginx configuration builder - NodeJS
Config:
new NginxBuilder({
outputPath: path.resolve(__dirname, "config"),
fileName: "docker.webserver.conf",
apps: [
{
name: "app1",
serverName: "app1.domain.local app1.domain.ch",
port: 80,
proxy: [
{
locationPath:' /api/',
host: "host.docker.internal",
path:'/api/',
port: 8003,
},
{
locationPath:' /api/docs/',
host: "host.docker.internal",
path:'/swagger/',
port: 8003,
},
{
locationPath: "^/api/app/(?<endpoint>.+)$",
path: "/api",
host: "$endpoint.app.external.ch",
options:{
locationPrefix:'~',
https: true,
rewrite:'^/api/app/(.+) /api break',
}
}
],
locations:[
{
locationPath:'/',
path: "/var/www/app1",
}
]
},
{
name: "app2",
serverName: "app2.domain.local app2.domain.ch",
port: 80,
proxy: [
{
locationPath:' /api/',
host: "host.docker.internal",
path:'/api/',
port: 8004,
},
{
locationPath:' /api/docs/',
host: "host.docker.internal",
path:'/swagger/',
port: 8004,
},
],
locations:[
{
locationPath:'/',
path: "/var/www/app2",
}
]
},
],
})
Result:
server
{
listen 80;
server_name app1.domain.local app1.domain.ch;
location /
{
root /var/www/app1;
try_files $uri $uri/ /index.html?$query_string;
}
location /api/
{
proxy_pass http://host.docker.internal:8003/api/;
}
location /api/docs/
{
proxy_pass http://host.docker.internal:8003/swagger/;
}
location ~ ^/api/app/(?<endpoint>.+)$ {
rewrite ^/api/app/(.+) /api break;
proxy_pass https://$endpoint.app.external.ch/api;
}
}
server
{
listen 80;
server_name app2.domain.local app2.domain.ch;
location /
{
root /var/www/app2;
try_files $uri $uri/ /index.html?$query_string;
}
location /api/
{
proxy_pass http://host.docker.internal:8004/api/;
}
location /api/docs/
{
proxy_pass http://host.docker.internal:8004/swagger/;
}
}
Installation:
npm i --save nginx-builder
How to use:
import { NginxBuilder } from 'nginx-builder'
const nginxBuilder = new NginxBuilder(yourConfig);
nginxBuilder.saveToFile(nginxBuilder.build(),{
spaces: 2, // Use 2 spaces for indentation
tabs: 0, // No tabs (use spaces)
dontJoinCurlyBracet: true // Place curly braces on new lines
})