npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

nginx-generator

v1.2.0

Published

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

Downloads

26

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:

$ npm install -g nginx-generator

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

$ 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

$ sudo service nginx reload

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

$ 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:

$ 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:

$ 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:

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

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:

LICENSE

Copyright 2014 Andrew Chilton [email protected].

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)