Defined Type: nginx::site

Defined in:
manifests/site.pp

Summary

Configure nginx site

Overview

Parameters:

  • proxy_target (String)

    sets the target for the nginx proxy

  • aws_access_key_id (String)

    sets the AWS key to use for Route53 challenge

  • aws_secret_access_key (String)

    sets the AWS secret key to use for the Route53 challenge

  • email (String)

    sets the contact address for the certificate

  • port (Integer) (defaults to: 443)

    sets the port to listen on

  • bind_addresses (Array[String]) (defaults to: ['*', '[::]'])

    sets the IP for the site

  • allow_ranges (Array[String]) (defaults to: [])

    restricts access to the site based on source IP

  • csp (String) (defaults to: "default-src 'self' http: https: ws: wss: data: blob: 'unsafe-inline'; frame-ancestors 'self';")

    sets the content security policy for the site

  • proxy_params (Hash[String, String]) (defaults to: {})

    sets extra options to use in the proxy config

  • custom_file (Optional[String]) (defaults to: undef)

    sets a total override for the contents of the nginx config

  • site (String) (defaults to: $title)

    sets the name of the site

  • users (Hash[String, String]) (defaults to: {})

    sets basic auth users and hashed passwords



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'manifests/site.pp', line 15

define nginx::site (
  String $proxy_target,
  String $aws_access_key_id,
  String $aws_secret_access_key,
  String $email,
  Integer $port = 443,
  Array[String] $bind_addresses = ['*', '[::]'],
  Array[String] $allow_ranges = [],
  String $csp = "default-src 'self' http: https: ws: wss: data: blob: 'unsafe-inline'; frame-ancestors 'self';",
  Hash[String, String] $proxy_params = {},
  Optional[String] $custom_file = undef,
  String $site = $title,
  Hash[String, String] $users = {},
) {
  include nginx

  $contents = $custom_file ? {
    undef   => template('nginx/site.conf.erb'),
    default => $custom_file,
  }

  $hook_script =  "#!/usr/bin/env bash
cp \$LEGO_CERT_PATH /etc/nginx/ssl/${site}.crt
cp \$LEGO_CERT_KEY_PATH /etc/nginx/ssl/${site}.key
/usr/bin/systemctl reload nginx"

  acme::certificate { $site:
    hook_script           => $hook_script,
    aws_access_key_id     => $aws_access_key_id,
    aws_secret_access_key => $aws_secret_access_key,
    email                 => $email,
  }

  -> file { "/etc/nginx/sites/${site}.conf":
    ensure  => file,
    owner   => 'root',
    group   => 'http',
    mode    => '0640',
    content => $contents,
    notify  => Service['nginx'],
  }

  if length($users) > 0 {
    file { "/etc/nginx/creds/${site}.htpasswd":
      ensure  => file,
      owner   => 'root',
      group   => 'http',
      mode    => '0640',
      content => template('nginx/htpasswd.erb'),
      notify  => Service['nginx'],
    }
  }
}