Compare commits

...

22 Commits

Author SHA1 Message Date
a4d8a46360 2.0.28 2019-01-19 15:57:50 +01:00
84e5c10129 fix(core): update 2019-01-19 15:57:49 +01:00
98a2871f08 2.0.27 2019-01-19 15:42:46 +01:00
9bb847210a fix(core): update 2019-01-19 15:42:45 +01:00
91d4ba5715 2.0.26 2019-01-19 15:41:51 +01:00
3ee2988964 fix(core): update 2019-01-19 15:41:51 +01:00
221f1f6237 2.0.25 2019-01-19 12:17:47 +01:00
0a6fbf588e fix(core): update 2019-01-19 12:17:47 +01:00
1a8546af6e 2.0.24 2019-01-19 11:07:14 +01:00
9e01bdb8e2 fix(core): update 2019-01-19 11:07:14 +01:00
33833fbc6c 2.0.23 2019-01-19 10:59:25 +01:00
97b5678fe4 fix(core): update 2019-01-19 10:59:24 +01:00
9b96984413 2.0.22 2019-01-19 03:21:27 +01:00
0de412b842 fix(core): update 2019-01-19 03:21:27 +01:00
64bcce9e23 2.0.21 2019-01-19 03:04:38 +01:00
390812ec33 fix(core): update 2019-01-19 03:04:38 +01:00
a672bb920f 2.0.20 2019-01-19 02:46:41 +01:00
c3fabb6107 fix(core): update 2019-01-19 02:46:41 +01:00
b4ebdbae47 2.0.19 2019-01-19 02:44:52 +01:00
c55d2dcf10 fix(core): update 2019-01-19 02:44:52 +01:00
7274d5ea8a 2.0.18 2019-01-19 02:25:35 +01:00
1ec733c2a9 fix(core): update 2019-01-19 02:25:34 +01:00
7 changed files with 30 additions and 18 deletions

2
package-lock.json generated
View File

@ -1,6 +1,6 @@
{
"name": "@pushrocks/smartnginx",
"version": "2.0.17",
"version": "2.0.28",
"lockfileVersion": 1,
"requires": true,
"dependencies": {

View File

@ -1,6 +1,6 @@
{
"name": "@pushrocks/smartnginx",
"version": "2.0.17",
"version": "2.0.28",
"private": false,
"description": "control nginx from node, TypeScript ready",
"main": "dist/index.js",

View File

@ -19,12 +19,14 @@ tap.test(`should produce an instance of NginxConfig`, async () => {
testNginxZone01 = new smartnginx.NginxHost(testSmartNginx, {
hostName: 'test100.bleu.de',
destination: '192.192.192.191',
destinationPort: 3000,
privateKey: 'some private',
publicKey: 'some public'
});
testNginxZone02 = new smartnginx.NginxHost(testSmartNginx, {
hostName: 'test102.bleu.de',
destination: '192.192.192.192',
destinationPort: 3050,
privateKey: 'some private',
publicKey: 'some public'
});

View File

@ -1,6 +1,7 @@
export interface IHostConfig {
hostName: string;
destination: string;
destinationPort: number;
privateKey: string;
publicKey: string;
}

View File

@ -21,6 +21,7 @@ export class NginxHost implements IHostConfig {
public hostName: string; // the host name e.g. domain name
public destination: string;
public destinationPort: number;
public configString: string; // the actual host config file as string
public privateKey: string;
public publicKey: string;
@ -29,7 +30,7 @@ export class NginxHost implements IHostConfig {
this.smartnginxInstance = smartnginxInstanceArg;
this.hostName = optionsArg.hostName;
this.destination = optionsArg.destination;
this.configString = snippets.getHostConfigString(optionsArg.hostName, optionsArg.destination);
this.destinationPort = optionsArg.destinationPort;
this.privateKey = optionsArg.privateKey;
this.publicKey = optionsArg.publicKey;
}
@ -42,7 +43,10 @@ export class NginxHost implements IHostConfig {
const filePathConfig = plugins.path.join(paths.nginxHostDirPath, `${this.hostName}.conf`);
const filePathPrivate = plugins.path.join(paths.nginxHostDirPath, `${this.hostName}.private.pem`);
const filePathPublic = plugins.path.join(paths.nginxHostDirPath, `${this.hostName}.public.pem`);
// writeConfig
this.configString = snippets.getHostConfigString(this.hostName, this.destination, this.destinationPort);
plugins.smartfile.memory.toFsSync(this.configString, filePathConfig);
// write ssl

View File

@ -78,7 +78,8 @@ export class SmartNginx {
await this.deployedHosts.forEach(async deployedHostArg => {
if (
hostCandidateArg.hostName === deployedHostArg.hostName &&
hostCandidateArg.destination === deployedHostArg.destination
hostCandidateArg.destination === deployedHostArg.destination &&
hostCandidateArg.destinationPort === deployedHostArg.destinationPort
) {
hostCounter++;
foundHost = true;

View File

@ -1,7 +1,7 @@
import * as plugins from './smartnginx.plugins';
import * as paths from './smartnginx.paths';
export let getBaseConfigString = () => {
let baseConfig = plugins.smartstring.indent.normalize(`
const baseConfig = plugins.smartstring.indent.normalize(`
user www-data;
worker_processes auto;
pid /run/nginx/nginx.pid;
@ -71,33 +71,37 @@ export let getBaseConfigString = () => {
return baseConfig;
};
export let getHostConfigString = (hostNameArg: string, destinationIpArg: string) => {
let hostConfig = plugins.smartstring.indent.normalize(`
export let getHostConfigString = (hostNameArg: string, destinationIpArg: string, destinationPortArg = 80) => {
const hostConfig = plugins.smartstring.indent.normalize(`
upstream ${hostNameArg} {
server ${destinationIpArg};
keepalive 100;
server ${destinationIpArg}:${destinationPortArg};
}
server {
# The keepalive parameter sets the maximum number of idle keepalive connections
# to upstream servers that are preserved in the cache of each worker process. When
# this number is exceeded, the least recently used connections are closed.
listen *:80 ;
server_name ${hostNameArg};
rewrite ^ https://${hostNameArg}$request_uri? permanent;
}
server {
listen *:443 ssl;
listen *:443 ssl http2;
server_name ${hostNameArg};
ssl_certificate ${paths.nginxHostDirPath}/${hostNameArg}.public.pem;
ssl_certificate_key ${paths.nginxHostDirPath}/${hostNameArg}.private.pem;
location / {
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://${hostNameArg};
}
location ~ /\.git {
deny all;
http2_push_preload on;
proxy_http_version 1.1;
proxy_redirect off;
proxy_buffering off;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://${hostNameArg};
}
}
`);