Forge Home


NGINX module for Puppet >=3.0x


8,858 latest version

3.6 quality score

We run a couple of automated
scans to help you access a
module's quality. Each module is
given a score based on how well
the author has formatted their
code and documentation and
modules are also checked for
malware using VirusTotal.

Please note, the information below
is for guidance only and neither of
these methods should be considered
an endorsement by Puppet.

Version information

  • 2.0.0 (latest)
  • 1.3.1
  • 1.3.0
  • 1.2.0
  • 1.1.0
  • 1.0.0
released Feb 2nd 2015

Start using this module

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

Add this module to your Puppetfile:

mod 'DracoBlue-nginx', '2.0.0'
Learn more about managing modules with a Puppetfile

Add this module to your Bolt project:

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

Manually install this module globally with Puppet module tool:

puppet module install DracoBlue-nginx --version 2.0.0

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.



DracoBlue/nginx — version 2.0.0 Feb 2nd 2015


A very slim nginx module for puppet.

pp-ningx is copyright 2014-2015 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


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,


This area will contain some templates, which are frequently used. They are available in the manifests/templates/ folder.


Redirect a given domain from to with an own nginx server entry.

nginx::templates::www_rewrite_http_server { "example-www-redirect":
  server_name => "",

Will generate:

server {
    listen 80;
    rewrite ^(.*)$1 permanent;

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.


  • 2.0.0 (2015/02/02)
    • removed symlink from tests folder (because they are not supported in packages)
    • [BC] removed unused nginx::base class
    • added puppet lint and puppet parser validate to travis tests
    • fixed line indention and some other things to make puppet-lint happy #17
    • [BC] renamed nginx::server::location::auth-basic to nginx::server::location::auth_basic for puppet 4.0 compatibility
    • added template nginx::templates::www_rewrite_http_server for redirect of e.g. to
  • 1.3.1 (2015/01/31)
    • fixed recursive symlinks in test folder
  • 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.