summaryrefslogtreecommitdiff
path: root/manifests/nginx_userdir.pp
blob: 39b6b9a20ecd147bb9a96f053b6fa0f4b78fe0bd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
68
69
# Configures nginx locations for user specific directories, where the
# username is a subdomain.
class profiles::nginx_userdir (
  $servername = $::fqdn,
) {
  include ::nginx

  # TODO wildcard certificate
  $_servername = regsubst($servername, '[.]', '\.', 'G', 'N')
  nginx::resource::server { "userdir ${servername}":
    server_name          => ["~^(?P<uname>[a-z][-a-z0-9]*)\\.${_servername}"],
    use_default_location => false,
    www_root             => '/home/$uname/.public',
    ssl                  => false,
    # *                  => letsencrypt::conf::nginx($servername),
    index_files => [
      'index.cgi',
      'index.php',
      'index.html',
      'index.htm',
    ],
  }

  $nginx_defaults = {
      server      => "userdir ${servername}",
      ssl         => false,
      ssl_only    => false,
      index_files => [],
  }

  nginx::resource::location { "userdir.${servername} /":
    location  => '/',
    autoindex => 'on',
    try_files => [
      '$uri',
      '$uri/',
      '=404',
    ],
    *         => $nginx_defaults,
  }

  include ::profiles::fcgiwrap
  nginx::resource::location { "userdir.${servername} cgi":
    location         => '~ \.cgi$',
    fastcgi          => 'unix:/run/fcgiwrap.socket',
    # TODO isn't socket name os dependant
    fastcgi_param    => {
      'PATH_INFO'    => '$fastcgi_script_name',
      'QUERY_STRING' => '$args',
    },
    *                => $nginx_defaults,
  }

  include ::profiles::phpfpm
  # TODO doesn't socket location depend on both os and php version
  nginx::resource::location { "userdir.${servername} php":
    location       => '~ \.php$',
    fastcgi        => 'unix:/run/php/php-fpm.sock',
    fastcgi_params => "${nginx::conf_dir}/snippets/fastcgi-php.conf",
    *              => $nginx_defaults,
  }

  nginx::resource::location { "userdir.${servername} deny .ht":
    location      => '~ /\.ht',
    location_deny => ['all'],
    *             => $nginx_defaults,
  }
  
}