A set of utilities for generating nginx configurations.
To install, simply run:
$ go get github.com/parkr/nginxconf/...
This command generates nginx
server blocks. It can be used to generate
one of three different types of sites:
- Static site (serve files from a directory)
- Proxy site (act as a reverse proxy to another server running on the same host)
- Redirect site (redirect any incoming traffic to another domain)
By default, it generates strong a strong SSL configuration based on Let's Encrypt conventions. It does not generate certificates for you, however.
These all print to stdout. You can redirect the contents to a file in your
1. Static site
To generate a static site, you'll need a directory with your static site to serve from. Then, simply run:
$ nginx-conf-gen -domain="example.org" \ -static -webroot=/var/www/html
This will serve the contents of
2. Proxy site
To generate a proxy site, you'll need to know what port to forward the traffic to.
$ nginx-conf-gen -domain="example.org" \ -proxy -port=8080
This will serve all traffic from your server running at
3. Redirect site
To generate a proxy site, you'll need a schema and host to redirect traffic
$ nginx-conf-gen -domain="example.org" \ -redirect="https://example.co"
This will redirect all traffic to
This command pulls down the MIME types from mime-db
and generates an nginx
types block. It is quite an extensive list but is
useful for serving static sites properly.
To run this command, you will need to know where your nginx configuration
lives. On my servers, it usually lives in
/opt/nginx/conf. There's a file
mime.types which I just overwrite:
$ nginx-mimes-gen > /opt/nginx/conf/mime.types
In the main
http block in your
nginx.conf file, ensure the line
include mime.types; exists. If it's not there, add it and reload nginx.
Code released under The MIT License. See LICENSE.md for details.