Forge Home


Slim nginx config generator


8,090 latest version

0.9 quality score

Version information

  • 0.0.1 (latest)
released Sep 2nd 2014
This version is compatible with:

Start using this module

  • r10k or Code Manager
  • Bolt
  • Manual installation
  • Direct download

Add this module to your Puppetfile:

mod 'Enucatl-nginx', '0.0.1'
Learn more about managing modules with a Puppetfile

Add this module to your Bolt project:

bolt module add Enucatl-nginx
Learn more about using this module with an existing project

Manually install this module globally with Puppet module tool:

puppet module install Enucatl-nginx --version 0.0.1

Direct download is not typically how you would use a Puppet module to manage your infrastructure, but you may want to download the module in order to inspect the code.



Enucatl/nginx — version 0.0.1 Sep 2nd 2014


A very slim nginx module for puppet.

pp-ningx is copyright 2014 by DracoBlue


Latest version from puppet forge:

$ puppet module install DracoBlue-nginx

Latest version from git.

$ cd modules
$ git clone nginx



# include package and server for nginx
include nginx

$server = ""

# define new server (/vhost)
nginx::server { $server:
  content => "listen *:80;
server_name $server;"

# define a location
nginx::server::location { "assets":
  location => "~ ^/",
  server => Nginx::Server[$server],
  content => "root /var/www/assets/;"

Result (/etc/nginx/conf.d/

server {
    listen *:80;

    location ~ ^/ {
        root /var/www/assets/;


There are only 3 classes in this puppet module.

  • public:
    • include nginx: makes sure that nginx::package and nginx::service is available
  • private
    • include nginx::package: is loaded by the nginx class, to ensure that the nginx package is available on the operating system
    • include nginx::service: is loaded by the nginx class, to ensure that the nginx service control is available
    • include nginx::base: is used by nginx::server::location and nginx::server to ensure that the server is reloaded on file changes


See the Example at the beginning for explanation how the nginx::server and nginx::server::location type work together.


Adds a new server in a file called /etc/nginx/conf.d/$name.conf.

nginx::server { "":
  server => '',
  content => "listen *:80;

See tests/ for more examples.


Adds a location block definition to the given $server.

nginx::server::location { "assets":
  server => Nginx::Server[''],
  location => '~ ^/assets/(.+)',
  content => "root /var/www;"

See tests/ for more examples.


Adds an alias definition to map to a $directory for to the given $location.

nginx::server::location::alias { "assets-directory":
  location => Nginx::Server::Location['assets'],
  directory => '/var/www/assets/$1'

See tests/ for more examples.


Adds allow and deny definitions to a given $location.

nginx::server::location::access { "assets-directory":
  location => Nginx::Server::Location['assets'],
  allow => ["", ""],
  deny => [""]

The access fragment will always put allow definitions before deny definitions. If you want to have some deny rules before the allow rules, use two access definitions (like in tests/

See tests/ for more examples.


Adds auth_basic and auth_basic_user_file definitions to a given $location.

Be sure that nginx can access the absolute path given to in $user_file. The $text must not contain quotation marks (").

nginx::server::location::auth-basic { "assets-directory":
  location => Nginx::Server::Location['assets'],
  text => 'This is restricted',
  user_file => '/etc/nginx/.htpasswd'

See tests/ for more examples.

(private) nginx::server::location::fragment

This type is used within nginx::server::location::access and other nginx::server::location::* types to generate the location fragment into the nginx::server::location.

Example usage (taken from nginx::server::location::access):

define nginx::server::location::access (
  $allow = [],
  $deny = [],
  $content = undef,
  $config_template = "nginx/conf.d/location/access.conf.erb",

  $location = undef,
  $ensure = present,
  $order = "050",
) {

  nginx::server::location::fragment { "access_${name}":
    content => template($config_template),

    location => $location,
    ensure => $ensure,
    order => $order,

Run tests

$ make test

Hint: The tests will need sudo rights and will write into /tmp/pp-nginx-results. Every other file should not be affected.


  • 1.3.0 (2014/05/18)
    • added message if no proper $server is given to location (e.g. if server_config_file_name parameter is missing) refs #11
    • tests use a specific facter version now refs #14
    • Use indention parameter to automagicly indent all given "content" lines refs #13
  • 1.2.0 (2014/03/17)
    • Changed properties for $location and $server to resources instead of strings #10
    • Removed $server parameter for nginx::server::location::* #9
  • 1.1.0 (2014/03/17)
    • added nginx::server::location::auth-basic #8
    • added base type nginx::server::location::fragment #7
    • added nginx::server::location::access #6
    • travis now tests multiple puppet versions #5
    • nginx::server::location::alias adds the alias definition, to the nginx location specified #3
  • 1.0.0 (2014/03/16)
    • Initial release


pp-nginx is licensed under the terms of MIT.