diff --git a/README.markdown b/README.markdown index 46afaaa54..1a37e27ca 100644 --- a/README.markdown +++ b/README.markdown @@ -66,3 +66,30 @@ Add an smtp proxy } } + +# Hiera Support +Define the nginx resources in Hiera. Here are the examples: + +
+nginx::nginx_upstreams: + 'puppet_rack_app': + ensure: present + members: + - localhost:3000 + - localhost:3001 + - localhost:3002 +nginx::nginx_vhosts: + 'www.puppetlabs.com': + www_root: '/var/www/www.puppetlabs.com' + 'rack.puppetlabs.com': + ensure: present + proxy: 'http://puppet_rack_app' +nginx::nginx_locations: + 'static': + location: '~ "^/static/[0-9a-fA-F]{8}\/(.*)$"' + vhost: www.puppetlabs.com + 'userContent': + location: /userContent + vhost: www.puppetlabs.com + www_root: /var/www/html +diff --git a/manifests/config.pp b/manifests/config.pp index cb1d65692..000afbeba 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -26,7 +26,8 @@ $proxy_cache_inactive = $nginx::params::nx_proxy_cache_inactive, $proxy_http_version = $nginx::params::nx_proxy_http_version, $types_hash_max_size = $nginx::params::nx_types_hash_max_size, - $types_hash_bucket_size = $nginx::params::nx_types_hash_bucket_size + $types_hash_bucket_size = $nginx::params::nx_types_hash_bucket_size, + $http_cfg_append = $nginx::params::nx_http_cfg_append ) inherits nginx::params { File { owner => 'root', diff --git a/manifests/init.pp b/manifests/init.pp index abd972b88..49651fda2 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -42,7 +42,11 @@ $configtest_enable = $nginx::params::nx_configtest_enable, $service_restart = $nginx::params::nx_service_restart, $mail = $nginx::params::nx_mail, - $server_tokens = $nginx::params::nx_server_tokens + $server_tokens = $nginx::params::nx_server_tokens, + $http_cfg_append = $nginx::params::nx_http_cfg_append, + $nginx_vhosts = {}, + $nginx_upstreams = {}, + $nginx_locations = {}, ) inherits nginx::params { include stdlib @@ -63,6 +67,7 @@ proxy_cache_inactive => $proxy_cache_inactive, confd_purge => $confd_purge, server_tokens => $server_tokens, + http_cfg_append => $http_cfg_append, require => Class['nginx::package'], notify => Class['nginx::service'], } @@ -72,6 +77,13 @@ service_restart => $service_restart, } + validate_hash($nginx_upstreams) + create_resources('nginx::resource::upstream', $nginx_upstreams) + validate_hash($nginx_vhosts) + create_resources('nginx::resource::vhost', $nginx_vhosts) + validate_hash($nginx_locations) + create_resources('nginx::resource::location', $nginx_locations) + # Allow the end user to establish relationships to the "main" class # and preserve the relationship to the implementation classes through # a transitive relationship to the composite class. diff --git a/manifests/params.pp b/manifests/params.pp index 54821330e..4e3bf0b6f 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -25,7 +25,9 @@ $nx_types_hash_bucket_size = 512 $nx_names_hash_bucket_size = 64 $nx_multi_accept = off - $nx_events_use = false # One of [kqueue|rtsig|epoll|/dev/poll|select|poll|eventport] or false to use OS default +# One of [kqueue|rtsig|epoll|/dev/poll|select|poll|eventport] +# or false to use OS default + $nx_events_use = false $nx_sendfile = on $nx_keepalive_timeout = 65 $nx_tcp_nodelay = on @@ -70,12 +72,16 @@ /(?i-mx:fedora|rhel|redhat|centos|scientific|suse|opensuse|amazon|gentoo)/ => 'nginx', } - # Service restart after Nginx 0.7.53 could also be just "/path/to/nginx/bin -s HUP" - # Some init scripts do a configtest, some don't. If configtest_enable it's true - # then service restart will take $nx_service_restart value, forcing configtest. + # Service restart after Nginx 0.7.53 could also be just + # "/path/to/nginx/bin -s HUP" Some init scripts do a configtest, some don't. + # If configtest_enable it's true then service restart will take + # $nx_service_restart value, forcing configtest. + $nx_configtest_enable = false $nx_service_restart = '/etc/init.d/nginx configtest && /etc/init.d/nginx restart' $nx_mail = false + $nx_http_cfg_append = false + } diff --git a/manifests/resource/vhost.pp b/manifests/resource/vhost.pp index bc7f7954d..28d82639d 100644 --- a/manifests/resource/vhost.pp +++ b/manifests/resource/vhost.pp @@ -158,6 +158,7 @@ fastcgi_script => $fastcgi_script, try_files => $try_files, www_root => $www_root, + index_files => $index_files, location_custom_cfg => $location_custom_cfg, notify => Class['nginx::service'], } diff --git a/spec/classes/package_spec.rb b/spec/classes/package_spec.rb index 6d04ff7b0..b1fcbc7a4 100644 --- a/spec/classes/package_spec.rb +++ b/spec/classes/package_spec.rb @@ -5,7 +5,6 @@ shared_examples 'redhat' do |operatingsystem| let(:facts) {{ :operatingsystem => operatingsystem }} it { should contain_package('nginx') } - it { should contain_package('GeoIP') } it { should contain_package('gd') } it { should contain_package('libXpm') } it { should contain_package('libxslt') } diff --git a/templates/conf.d/nginx.conf.erb b/templates/conf.d/nginx.conf.erb index 0f3dd846d..06f68400c 100644 --- a/templates/conf.d/nginx.conf.erb +++ b/templates/conf.d/nginx.conf.erb @@ -29,16 +29,22 @@ http { keepalive_timeout <%= scope.lookupvar('nginx::params::nx_keepalive_timeout')%>; tcp_nodelay <%= scope.lookupvar('nginx::params::nx_tcp_nodelay')%>; - <% if scope.lookupvar('nginx::params::nx_gzip') == 'on' %> +<% if scope.lookupvar('nginx::params::nx_gzip') == 'on' %> gzip on; gzip_disable "MSIE [1-6]\.(?!.*SV1)"; - <% end -%> +<% end -%> <% if @proxy_cache_path -%> proxy_cache_path <%= @proxy_cache_path %> levels=<%= @proxy_cache_levels %> keys_zone=<%= @proxy_cache_keys_zone %> max_size=<%= @proxy_cache_max_size %> inactive=<%= @proxy_cache_inactive %>; <% end -%> +<% if @http_cfg_append -%><% @http_cfg_append.sort_by{|k,v| k}.each do |key,value| -%> + <%= key %> <%= value %>; +<% end -%> +<% end -%> + include /etc/nginx/conf.d/*.conf; + } <% if scope.lookupvar('nginx::mail') %> mail { diff --git a/templates/vhost/vhost_location_empty.erb b/templates/vhost/vhost_location_empty.erb index 420f5c6d7..ce53e1827 100644 --- a/templates/vhost/vhost_location_empty.erb +++ b/templates/vhost/vhost_location_empty.erb @@ -1,5 +1,5 @@ location <%= @location %> { -<% @location_custom_cfg.sort_by {|k,v| k}.each do |key,value| -%> +<% if @location_custom_cfg -%><% @location_custom_cfg.sort_by {|k,v| k}.each do |key,value| -%> <%= key %> <%= value %>; -<% end -%> +<% end -%><% end -%> }