Compare commits
16 Commits
Author | SHA1 | Date | |
---|---|---|---|
042167c01e | |||
db38d038ef | |||
a4d8a46360 | |||
84e5c10129 | |||
98a2871f08 | |||
9bb847210a | |||
91d4ba5715 | |||
3ee2988964 | |||
221f1f6237 | |||
0a6fbf588e | |||
1a8546af6e | |||
9e01bdb8e2 | |||
33833fbc6c | |||
97b5678fe4 | |||
9b96984413 | |||
0de412b842 |
2
package-lock.json
generated
2
package-lock.json
generated
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartnginx",
|
"name": "@pushrocks/smartnginx",
|
||||||
"version": "2.0.21",
|
"version": "2.0.29",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartnginx",
|
"name": "@pushrocks/smartnginx",
|
||||||
"version": "2.0.21",
|
"version": "2.0.29",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "control nginx from node, TypeScript ready",
|
"description": "control nginx from node, TypeScript ready",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
|
@ -19,12 +19,14 @@ tap.test(`should produce an instance of NginxConfig`, async () => {
|
|||||||
testNginxZone01 = new smartnginx.NginxHost(testSmartNginx, {
|
testNginxZone01 = new smartnginx.NginxHost(testSmartNginx, {
|
||||||
hostName: 'test100.bleu.de',
|
hostName: 'test100.bleu.de',
|
||||||
destination: '192.192.192.191',
|
destination: '192.192.192.191',
|
||||||
|
destinationPort: 3000,
|
||||||
privateKey: 'some private',
|
privateKey: 'some private',
|
||||||
publicKey: 'some public'
|
publicKey: 'some public'
|
||||||
});
|
});
|
||||||
testNginxZone02 = new smartnginx.NginxHost(testSmartNginx, {
|
testNginxZone02 = new smartnginx.NginxHost(testSmartNginx, {
|
||||||
hostName: 'test102.bleu.de',
|
hostName: 'test102.bleu.de',
|
||||||
destination: '192.192.192.192',
|
destination: '192.192.192.192',
|
||||||
|
destinationPort: 3050,
|
||||||
privateKey: 'some private',
|
privateKey: 'some private',
|
||||||
publicKey: 'some public'
|
publicKey: 'some public'
|
||||||
});
|
});
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
export interface IHostConfig {
|
export interface IHostConfig {
|
||||||
hostName: string;
|
hostName: string;
|
||||||
destination: string;
|
destination: string;
|
||||||
|
destinationPort: number;
|
||||||
privateKey: string;
|
privateKey: string;
|
||||||
publicKey: string;
|
publicKey: string;
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,7 @@ export class NginxHost implements IHostConfig {
|
|||||||
|
|
||||||
public hostName: string; // the host name e.g. domain name
|
public hostName: string; // the host name e.g. domain name
|
||||||
public destination: string;
|
public destination: string;
|
||||||
|
public destinationPort: number;
|
||||||
public configString: string; // the actual host config file as string
|
public configString: string; // the actual host config file as string
|
||||||
public privateKey: string;
|
public privateKey: string;
|
||||||
public publicKey: string;
|
public publicKey: string;
|
||||||
@ -29,7 +30,7 @@ export class NginxHost implements IHostConfig {
|
|||||||
this.smartnginxInstance = smartnginxInstanceArg;
|
this.smartnginxInstance = smartnginxInstanceArg;
|
||||||
this.hostName = optionsArg.hostName;
|
this.hostName = optionsArg.hostName;
|
||||||
this.destination = optionsArg.destination;
|
this.destination = optionsArg.destination;
|
||||||
this.configString = snippets.getHostConfigString(optionsArg.hostName, optionsArg.destination);
|
this.destinationPort = optionsArg.destinationPort;
|
||||||
this.privateKey = optionsArg.privateKey;
|
this.privateKey = optionsArg.privateKey;
|
||||||
this.publicKey = optionsArg.publicKey;
|
this.publicKey = optionsArg.publicKey;
|
||||||
}
|
}
|
||||||
@ -42,7 +43,10 @@ export class NginxHost implements IHostConfig {
|
|||||||
const filePathConfig = plugins.path.join(paths.nginxHostDirPath, `${this.hostName}.conf`);
|
const filePathConfig = plugins.path.join(paths.nginxHostDirPath, `${this.hostName}.conf`);
|
||||||
const filePathPrivate = plugins.path.join(paths.nginxHostDirPath, `${this.hostName}.private.pem`);
|
const filePathPrivate = plugins.path.join(paths.nginxHostDirPath, `${this.hostName}.private.pem`);
|
||||||
const filePathPublic = plugins.path.join(paths.nginxHostDirPath, `${this.hostName}.public.pem`);
|
const filePathPublic = plugins.path.join(paths.nginxHostDirPath, `${this.hostName}.public.pem`);
|
||||||
|
|
||||||
|
|
||||||
// writeConfig
|
// writeConfig
|
||||||
|
this.configString = snippets.getHostConfigString(this.hostName, this.destination, this.destinationPort);
|
||||||
plugins.smartfile.memory.toFsSync(this.configString, filePathConfig);
|
plugins.smartfile.memory.toFsSync(this.configString, filePathConfig);
|
||||||
|
|
||||||
// write ssl
|
// write ssl
|
||||||
|
@ -78,7 +78,8 @@ export class SmartNginx {
|
|||||||
await this.deployedHosts.forEach(async deployedHostArg => {
|
await this.deployedHosts.forEach(async deployedHostArg => {
|
||||||
if (
|
if (
|
||||||
hostCandidateArg.hostName === deployedHostArg.hostName &&
|
hostCandidateArg.hostName === deployedHostArg.hostName &&
|
||||||
hostCandidateArg.destination === deployedHostArg.destination
|
hostCandidateArg.destination === deployedHostArg.destination &&
|
||||||
|
hostCandidateArg.destinationPort === deployedHostArg.destinationPort
|
||||||
) {
|
) {
|
||||||
hostCounter++;
|
hostCounter++;
|
||||||
foundHost = true;
|
foundHost = true;
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import * as plugins from './smartnginx.plugins';
|
import * as plugins from './smartnginx.plugins';
|
||||||
import * as paths from './smartnginx.paths';
|
import * as paths from './smartnginx.paths';
|
||||||
export let getBaseConfigString = () => {
|
export let getBaseConfigString = () => {
|
||||||
let baseConfig = plugins.smartstring.indent.normalize(`
|
const baseConfig = plugins.smartstring.indent.normalize(`
|
||||||
user www-data;
|
user www-data;
|
||||||
worker_processes auto;
|
worker_processes auto;
|
||||||
pid /run/nginx/nginx.pid;
|
pid /run/nginx/nginx.pid;
|
||||||
@ -71,11 +71,11 @@ export let getBaseConfigString = () => {
|
|||||||
return baseConfig;
|
return baseConfig;
|
||||||
};
|
};
|
||||||
|
|
||||||
export let getHostConfigString = (hostNameArg: string, destinationIpArg: string) => {
|
export let getHostConfigString = (hostNameArg: string, destinationIpArg: string, destinationPortArg = 80) => {
|
||||||
let hostConfig = plugins.smartstring.indent.normalize(`
|
const hostConfig = plugins.smartstring.indent.normalize(`
|
||||||
upstream ${hostNameArg} {
|
upstream ${hostNameArg} {
|
||||||
keepalive 100;
|
keepalive 100;
|
||||||
server ${destinationIpArg};
|
server ${destinationIpArg}:${destinationPortArg};
|
||||||
}
|
}
|
||||||
|
|
||||||
server {
|
server {
|
||||||
@ -88,20 +88,19 @@ export let getHostConfigString = (hostNameArg: string, destinationIpArg: string)
|
|||||||
}
|
}
|
||||||
|
|
||||||
server {
|
server {
|
||||||
listen *:443 ssl;
|
listen *:443 ssl http2;
|
||||||
server_name ${hostNameArg};
|
server_name ${hostNameArg};
|
||||||
ssl_certificate ${paths.nginxHostDirPath}/${hostNameArg}.public.pem;
|
ssl_certificate ${paths.nginxHostDirPath}/${hostNameArg}.public.pem;
|
||||||
ssl_certificate_key ${paths.nginxHostDirPath}/${hostNameArg}.private.pem;
|
ssl_certificate_key ${paths.nginxHostDirPath}/${hostNameArg}.private.pem;
|
||||||
|
|
||||||
location / {
|
location / {
|
||||||
proxy_http_version 1.1;
|
http2_push_preload on;
|
||||||
proxy_set_header Host $http_host;
|
proxy_http_version 1.1;
|
||||||
proxy_set_header X-Real-IP $remote_addr;
|
proxy_buffering off;
|
||||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
proxy_set_header Host $http_host;
|
||||||
proxy_set_header X-Forwarded-Proto $scheme;
|
proxy_set_header X-Real-IP $remote_addr;
|
||||||
proxy_set_header Connection "Keep-Alive";
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||||
proxy_set_header Proxy-Connection "Keep-Alive";
|
proxy_set_header X-Forwarded-Proto $scheme;
|
||||||
proxy_pass http://${hostNameArg};
|
proxy_pass http://${hostNameArg};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
`);
|
`);
|
||||||
|
Reference in New Issue
Block a user