location.pp 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. # define: nginx::resource::location
  2. #
  3. # This definition creates a new location entry within a virtual host
  4. #
  5. # Parameters:
  6. # [*ensure*] - Enables or disables the specified location (present|absent)
  7. # [*vhost*] - Defines the default vHost for this location entry to include with
  8. # [*location*] - Specifies the URI associated with this location entry
  9. # [*www_root*] - Specifies the location on disk for files to be read from. Cannot be set in conjunction with $proxy
  10. # [*index_files*] - Default index files for NGINX to read when traversing a directory
  11. # [*proxy*] - Proxy server(s) for a location to connect to. Accepts a single value, can be used in conjunction
  12. # with nginx::resource::upstream
  13. # [*proxy_read_timeout*] - Override the default the proxy read timeout value of 90 seconds
  14. # [*ssl*] - Indicates whether to setup SSL bindings for this location.
  15. # [*location_alias*] - Path to be used as basis for serving requests for this location
  16. # [*option*] - Reserved for future use
  17. #
  18. # Actions:
  19. #
  20. # Requires:
  21. #
  22. # Sample Usage:
  23. # nginx::resource::location { 'test2.local-bob':
  24. # ensure => present,
  25. # www_root => '/var/www/bob',
  26. # location => '/bob',
  27. # vhost => 'test2.local',
  28. # }
  29. define nginx::resource::location(
  30. $ensure = present,
  31. $vhost = undef,
  32. $www_root = undef,
  33. $index_files = ['index.html', 'index.htm', 'index.php'],
  34. $proxy = undef,
  35. $proxy_read_timeout = $nginx::params::nx_proxy_read_timeout,
  36. $ssl = false,
  37. $location_alias = undef,
  38. $option = undef,
  39. $location
  40. ) {
  41. File {
  42. owner => 'root',
  43. group => 'root',
  44. mode => '0644',
  45. notify => Class['nginx::service'],
  46. }
  47. ## Shared Variables
  48. $ensure_real = $ensure ? {
  49. 'absent' => absent,
  50. default => file,
  51. }
  52. # Use proxy template if $proxy is defined, otherwise use directory template.
  53. if ($proxy != undef) {
  54. $content_real = template('nginx/vhost/vhost_location_proxy.erb')
  55. } elsif ($location_alias != undef) {
  56. $content_real = template('nginx/vhost/vhost_location_alias.erb')
  57. } else {
  58. $content_real = template('nginx/vhost/vhost_location_directory.erb')
  59. }
  60. ## Check for various error condtiions
  61. if ($vhost == undef) {
  62. fail('Cannot create a location reference without attaching to a virtual host')
  63. }
  64. if (($www_root == undef) and ($proxy == undef) and ($location_alias == undef)) {
  65. fail('Cannot create a location reference without a www_root, proxy or location_alias defined')
  66. }
  67. if (($www_root != undef) and ($proxy != undef)) {
  68. fail('Cannot define both directory and proxy in a virtual host')
  69. }
  70. ## Create stubs for vHost File Fragment Pattern
  71. file {"${nginx::config::nx_temp_dir}/nginx.d/${vhost}-500-${name}":
  72. ensure => $ensure_real,
  73. content => $content_real,
  74. }
  75. ## Only create SSL Specific locations if $ssl is true.
  76. if ($ssl == 'true') {
  77. file {"${nginx::config::nx_temp_dir}/nginx.d/${vhost}-800-${name}-ssl":
  78. ensure => $ensure_real,
  79. content => $content_real,
  80. }
  81. }
  82. }