1.0.4 • Published 3 years ago

nv-cli-nginx-conf v1.0.4

Weekly downloads
-
License
ISC
Repository
-
Last release
3 years ago

nv-cli-nginx-conf

  • nv-cli-nginx-conf
  • cli tool, nginx conf for a special format

install

  • npm install nv-cli-nginx-conf -g

usage

ngx_conf_init

    root@dev:/home/dev/NODE# ngx_conf_init -h
    Usage: ngx_conf_init [options]
    Options:
        -o, --output        output js file,default stdout
        -h, --help          usage

    root@dev:/home/dev/NODE#

examples

# ngx_conf_init -o nginx.conf

ngx_conf_srv

    root@dev:/home/dev/NODE# ngx_conf_srv -h
    Usage: ngx_conf_srv [options]
    Options:
        -n, --name          conf file name
        -a, --add           add server with ip ,port,domain,ssl,ssl_pem,ssl_key
        -d, --del           delete server with ip,port
        -l, --list          list server
        -g, --get           get server with ip,port
        -i, --ip            server ip
        -p, --port          server port
        -m, --domain        main domain
        -s, --ssl           enable ssl
        -e, --pem           ssl cert pem path
        -k, --key           ssl cert key path
        -o, --output        output js file,default stdout
        -h, --help          usage

examples

add server

//add server
# ngx_conf_srv  -a -n nginx.conf -i 127.0.0.1 -p 443 -m local.xyz -s -e /cert/0.pem  -k /cert/0.key -o nginx.conf
# ngx_conf_srv  -a -n nginx.conf -i 127.0.0.1 -p 883 -m dev.xyz -s -e /cert/1.pem  -k /cert/1.key -o nginx.conf

list server

#ngx_conf_srv  -l -n nginx.conf
[ '127.0.0.1:443', '127.0.0.1:883' ]

delete server

#ngx_conf_srv  -d -n nginx.conf -i 127.0.0.1 -p 883 -o nginx.conf
#ngx_conf_srv  -l -n nginx.conf
[ '127.0.0.1:443' ]
# 

get server

 //get server
 #ngx_conf_srv  -g -n nginx.conf -i 127.0.0.1 -p 443
 listen 127.0.0.1:443 ssl;
 server_name *.local.xyz;
 ssl on;
 ssl_certificate /cert/0.pem;
 ssl_certificate_key /cert/0.key;
 if ($http_host ~* "^(.*?)local\.xyz$") {
     set $domain $1;

 }
 location / {
     tcp_nodelay on;
     proxy_set_header Host $host;
     proxy_set_header X-Real-IP $remote_addr;
     proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

 }
 location /static {

 }
 location /http {
     tcp_nodelay on;
     proxy_set_header Host $host;
     proxy_set_header X-Real-IP $remote_addr;
     proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

 }
 location /ws {
     proxy_http_version 1.1;
     proxy_set_header Upgrade $http_upgrade;
     proxy_set_header Connection $connection_upgrade;
     proxy_set_header Host $host;
     proxy_set_header X-Real-IP $remote_addr;
     proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
 }

ngx_conf_app

    root@dev:/home/dev/NODE# ngx_conf_app -h
    Usage: ngx_conf_app [options]
    Options:
        -n, --name             conf file name
        -a, --add              add app with ip ,port,subdomain,static_dir,cmmn_proxy_port,http_proxy_port,ws_proxy_port
        -d, --del              delete app with ip,port,port,subdomain
        -l, --list             list app with ip,port
        -g, --get              get app with ip,port,subdomain
        -i, --ip               server ip
        -p, --port             server port
        -m, --subdomain        sub domain
        -t, --static           static dir
        -c, --cmmn             common service proxy port
        -x, --http             http/https get post... service proxy port
        -w, --ws               websocket service proxy port
        -o, --output           output js file,default stdout
        -h, --help             usage

    root@dev:/home/dev/NODE#

examples

add app

 //add app
 ngx_conf_app  -a -n nginx.conf -i 127.0.0.1 -p 443 -m json       -t /json/       -c 10001 -x 10002 -w 10003 -o nginx.conf
 ngx_conf_app  -a -n nginx.conf -i 127.0.0.1 -p 443 -m img        -t /img/        -c 20001 -x 20002 -w 20003 -o nginx.conf
 ngx_conf_app  -a -n nginx.conf -i 127.0.0.1 -p 443 -m video      -t /video/      -c 30001 -x 30002 -w 30003 -o nginx.conf
 ngx_conf_app  -a -n nginx.conf -i 127.0.0.1 -p 443 -m audio      -t /audio/      -c 40001 -x 40002 -w 40003 -o nginx.conf
 ngx_conf_app  -a -n nginx.conf -i 127.0.0.1 -p 443 -m file       -t /file/       -c 50001 -x 50002 -w 50003 -o nginx.conf
 ngx_conf_app  -a -n nginx.conf -i 127.0.0.1 -p 443 -m doc        -t /doc/        -c 60001 -x 60002 -w 60003 -o nginx.conf
 ngx_conf_app  -a -n nginx.conf -i 127.0.0.1 -p 443 -m db         -t /postgre/    -c 70001 -x 70002 -w 70003 -o nginx.conf
 ngx_conf_app  -a -n nginx.conf -i 127.0.0.1 -p 443 -m bigdata    -t /scylladb/   -c 80001 -x 80002 -w 80003 -o nginx.conf
 ngx_conf_app  -a -n nginx.conf -i 127.0.0.1 -p 443 -m nlp        -t /nlp/        -c 90001 -x 90002 -w 90003 -o nginx.conf

list app

 //list app
 #ngx_conf_app  -l -n nginx.conf -i 127.0.0.1 -p 443
 {
   json: App {
     subdomain: 'json',
     static: '/json/',
     cmmn_proxy_port: '10001',
     http_proxy_port: '10002',
     ws_proxy_port: '10003'
   },
   img: App {
     subdomain: 'img',
     static: '/img/',
     cmmn_proxy_port: '20001',
     http_proxy_port: '20002',
     ws_proxy_port: '20003'
   },
   video: App {
     subdomain: 'video',
     static: '/video/',
     cmmn_proxy_port: '30001',
     http_proxy_port: '30002',
     ws_proxy_port: '30003'
   },
   audio: App {
     subdomain: 'audio',
     static: '/audio/',
     cmmn_proxy_port: '40001',
     http_proxy_port: '40002',
     ws_proxy_port: '40003'
   },
   file: App {
     subdomain: 'file',
     static: '/file/',
     cmmn_proxy_port: '50001',
     http_proxy_port: '50002',
     ws_proxy_port: '50003'
   },
   doc: App {
     subdomain: 'doc',
     static: '/doc/',
     cmmn_proxy_port: '60001',
     http_proxy_port: '60002',
     ws_proxy_port: '60003'
   },
   db: App {
     subdomain: 'db',
     static: '/postgre/',
     cmmn_proxy_port: '70001',
     http_proxy_port: '70002',
     ws_proxy_port: '70003'
   },
   bigdata: App {
     subdomain: 'bigdata',
     static: '/scylladb/',
     cmmn_proxy_port: '80001',
     http_proxy_port: '80002',
     ws_proxy_port: '80003'
   },
   nlp: App {
     subdomain: 'nlp',
     static: '/nlp/',
     cmmn_proxy_port: '90001',
     http_proxy_port: '90002',
     ws_proxy_port: '90003'
   }
 }

get app

//get app

#ngx_conf_app  -g -n nginx.conf -i 127.0.0.1 -p 443 -m nlp
{
  subdomain: 'nlp',
  static: '/nlp/',
  cmmn_proxy_port: '90001',
  http_proxy_port: '90002',
  ws_proxy_port: '90003'
}
#

delete app

 //delete app
 ngx_conf_app -d -n nginx.conf -i 127.0.0.1 -p 443 -m file -o nginx.conf

LICENSE

  • ISC