Skip to content

Commit

Permalink
Merge pull request #1357 from absltkaos/add_limit_req_support
Browse files Browse the repository at this point in the history
Add support for limit_req_zone in main nginx config and limit_req: Fixes #1134
  • Loading branch information
bastelfreak committed Nov 18, 2019
2 parents 1cbde6c + a4e5c1e commit 380c1c9
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
$global_owner = $nginx::global_owner
$global_group = $nginx::global_group
$global_mode = $nginx::global_mode
$limit_req_zone = $nginx::limit_req_zone
$log_dir = $nginx::log_dir
$log_user = $nginx::log_user
$log_group = $nginx::log_group
Expand Down
1 change: 1 addition & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
$global_owner = $nginx::params::global_owner,
$global_group = $nginx::params::global_group,
$global_mode = $nginx::params::global_mode,
Optional[Variant[String[1], Array[String[1]]]] $limit_req_zone = undef,
Stdlib::Absolutepath $log_dir = $nginx::params::log_dir,
String[1] $log_user = $nginx::params::log_user,
String[1] $log_group = $nginx::params::log_group,
Expand Down
3 changes: 3 additions & 0 deletions manifests/resource/location.pp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@
# [*raw_append*] - A single string, or an array of strings to
# append to the location directive (after custom_cfg directives). NOTE:
# YOU are responsible for a semicolon on each line that requires one.
# [*limit_zone*] - Apply a limit_req_zone to the location. Expects a string indicating a
# previously defined limit_req_zone in the main nginx configuration
# [*location_custom_cfg*] - Expects a hash with custom directives, cannot
# be used with other location types (proxy, fastcgi, root, or stub_status)
# [*location_cfg_prepend*] - Expects a hash with extra directives to put
Expand Down Expand Up @@ -214,6 +216,7 @@
Boolean $ssl = false,
Boolean $ssl_only = false,
Optional[String] $location_alias = undef,
Optional[String[1]] $limit_zone = undef,
Optional[Enum['any', 'all']] $location_satisfy = undef,
Optional[Array] $location_allow = undef,
Optional[Array] $location_deny = undef,
Expand Down
12 changes: 12 additions & 0 deletions spec/classes/nginx_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,18 @@
value: 'warn',
match: ' error_log /var/log/nginx/error.log warn;'
},
{
title: 'should set limit_req_zone',
attr: 'limit_req_zone',
value: [
'$binary_remote_addr zone=myzone1:10m rate=5r/s',
'$binary_remote_addr zone=myzone2:10m rate=5r/s'
],
match: [
' limit_req_zone $binary_remote_addr zone=myzone1:10m rate=5r/s;',
' limit_req_zone $binary_remote_addr zone=myzone2:10m rate=5r/s;'
]
},
{
title: 'should set pid',
attr: 'pid',
Expand Down
6 changes: 6 additions & 0 deletions spec/defines/resource_location_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@
value: 'any',
match: ' satisfy any;'
},
{
title: 'should set limit_zone',
attr: 'limit_zone',
value: 'myzone1',
match: ' limit_req zone=myzone1;'
},
{
title: 'should set expires',
attr: 'expires',
Expand Down
10 changes: 10 additions & 0 deletions templates/conf.d/nginx.conf.erb
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,16 @@ http {
error_log <%= @nginx_error_log %> <%= @nginx_error_log_severity %>;
<% end -%>
<% if @limit_req_zone -%>
<% if @limit_req_zone.is_a?(Array) -%>
<%- @limit_req_zone.each do |limit_req_zone_item| -%>
limit_req_zone <%= limit_req_zone_item %>;
<% end -%>
<% else -%>
limit_req_zone <%= @limit_req_zone %>;
<% end -%>
<% end -%>
<% if @sendfile == 'on' -%>
sendfile on;
<%- if @http_tcp_nopush == 'on' -%>
Expand Down
3 changes: 3 additions & 0 deletions templates/server/location_header.erb
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,6 @@
rewrite <%= rewrite_rule %>;
<%- end -%>
<% end -%>
<% if @limit_zone -%>
limit_req zone=<%= @limit_zone %>;
<% end -%>

0 comments on commit 380c1c9

Please sign in to comment.