# nk-nginx-generator

> Generate simple Nginx 'vhosts' with a simple library/cli tool.

Latest version **1.1.6** (published 2016-08-09) · Apache 2.0 license · 0 weekly downloads

## Install

```sh
npm install nk-nginx-generator
pnpm add nk-nginx-generator
yarn add nk-nginx-generator
bun add nk-nginx-generator
```

Provides the command `nginx-generator`.

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.6 |
| Published | 2016-08-09 |
| First published | 2016-07-11 |
| Weekly downloads | 0 |
| License | Apache 2.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Known vulnerabilities | 0 (+9 in 1 direct dependencies) |
| Install scripts | no |
| Author | Andrew Chilton |
| Maintainers | nketchum |
| Keywords | nginx, proxy, http, redirect |

## Links

- npm: https://www.npmjs.com/package/nk-nginx-generator
- Repository: https://github.com/nketchum/nginx-generator
- Homepage: https://github.com/chilts/nginx-generator
- Issues: https://github.com/chilts/nginx-generator/issues
- npm.io page: https://npm.io/package/nk-nginx-generator

## Dependencies (3)

- [xtend](https://npm.io/package/xtend.md) ^4.0.0
- [minimist](https://npm.io/package/minimist.md) ^1.1.0
- [handlebars](https://npm.io/package/handlebars.md) ^2.0.0

## Recent versions

- 1.1.6 (latest) — 2016-08-09
- 1.1.5 — 2016-07-29
- 1.1.4 — 2016-07-29
- 1.1.3 — 2016-07-27
- 1.1.2 — 2016-07-26
- 1.1.1 — 2016-07-26
- 1.1.0 — 2016-07-11

## README

# nginx-generator #

Easy simple way to create Nginx vhost files for fairly simple sites, such as a proxy to a Node.js server, a redirect
from one domain to another, serving a static site or setting up a config to serve multiple static sites from one
directory.

## Synopsis ##

To install:

```bash
$ npm install -g nginx-generator
```

To generate a simple redirect from `www.chilts.org` to `chilts.org`, just do:

```bash
$ nginx-generator \
      --name org-chilts-www \
      --domain www.chilts.org \
      --type redirect \
      --var to=chilts.org \
      /etc/nginx/sites-enabled/org-chilts-www
```

Then reload Nginx

```bash
$ sudo service nginx reload
```

Your vars can also be read from a JSON file, such as this:

```bash
$ echo '{"to":"chilts.org"}' > vars.json
$ nginx-generator \
      --name org-chilts-www \
      --domain www.chilts.org \
      --type redirect \
      --data vars.json \
      /etc/nginx/sites-enabled/org-chilts-www
```

## Proxy ##

To generate a proxy that will forward requests elsewhere, just pass the usual three `--name`, `--domain` and `--type`
then pass both `host` and `port` as `--var` variables:

```
$ nginx-generator \
      --name org-chilts \
      --domain chilts.org \
      --type proxy \
      --var host=localhost \
      --var port=8000 \
      /etc/nginx/sites-enabled/org-chilts
```

## Static Site ##

To generate a vhost that will serve a static site, just pass the usual three `--name`, `--domain` and `--type` then
pass `dir` as a `--var`:

```
$ nginx-generator \
      --name org-chilts-static \
      --domain static-chilts.org \
      --type static \
      --var dir=/home/chilts/htdocs \
      /etc/nginx/sites-enabled/org-chilts-static
```

## Redirect ##

To generate a redirect, just pass the usual three `--name`, `--domain` and `--type` then pass `to` as a `--var`:

```bash
$ nginx-generator \
      --name org-chilts-www \
      --domain www.chilts.org \
      --type redirect \
      --var to=chilts.org \
      /etc/nginx/sites-enabled/org-chilts-www
```

## Catchall (for multiple static sites) ##

To generate a catchall for multiple static sites, create a directory which will hold all of the sites, then create a
directory for each site, named after the host it will serve. For example, this will serve `example.com`, `chilts.org`
and `nodejs.nz`:

```sh
$ mkdir /var/lib/sites
$ mkdir /var/lib/sites/example.com
$ mkdir /var/lib/sites/chilts.org
$ mkdir /var/lib/sites/nodejs.nz
```

Then, create this special vhost config:

```bash
$ nginx-generator \
      --name vhost \
      --domain _ \
      --type vhost \
      --var dir=/var/lib/sites \
      /etc/nginx/sites-enabled/vhost
```

## DRUPAL 8 ##

To generate a single Drupal 8 installation, pass the usual three `--name`, `--domain` and `--type` then
pass `dir` as a `--var`:

```
$ nginx-generator \
      --name org-chilts-drupal8 \
      --domain static-drupal8.org \
      --type drupal8 \
      --var dir=/home/chilts/htdocs \
      /etc/nginx/sites-enabled/org-chilts-drupal8
```

## Roadmap ##

* add ability to set and define config for basic auth for any site
* add ability to make a site serve over https with config for certs

## Other Nginx Packages ##

There are some other Nginx packages out there such as:

* https://www.npmjs.org/package/nginx-vhosts
* https://www.npmjs.org/package/ngineer
* https://www.npmjs.org/package/nginx-conf
* https://www.npmjs.org/package/nodeginx

However, I didn't want to control Nginx itself like `nginx-vhosts` and `ngineer` does, especially on Debian or Ubuntu
machines since upstart already does this. All I wanted to do was template in some simple vhosts in a programmatic
(library or CLI program) way. Also, `nginx-conf` is too complicated since that's for the main Nginx config. `nodeginx`
is closest to this package in terms of functionality.

## AUTHOR ##

Written by [Andrew Chilton](http://chilts.org/):

* [Blog](http://chilts.org/)
* [GitHub](https://github.com/chilts)
* [Twitter](https://twitter.com/andychilton)
* [Instagram](http://instagram.com/thechilts)

## LICENSE ##

Copyright 2014 Andrew Chilton <andychilton@gmail.com>.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

(Ends)

---
_Source: https://npm.io/package/nk-nginx-generator · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
