Skip to content

Commit 1eed398

Browse files
author
Steven Post
committed
Apache: add support for the ProxyPassMatch directive
1 parent 6c78b79 commit 1eed398

4 files changed

Lines changed: 58 additions & 1 deletion

File tree

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1247,6 +1247,10 @@ Array of IPs to exclude from mod_security rule matching
12471247

12481248
Specifies URLs you do not want to proxy. This parameter is meant to be used in combination with [`proxy_dest`](#proxy_dest).
12491249

1250+
#####`no_proxy_uris_match`
1251+
1252+
This directive is equivalent to `no_proxy_uris`, but takes regular expressions.
1253+
12501254
#####`proxy_preserve_host`
12511255

12521256
Sets the [ProxyPreserveHost Directive](http://httpd.apache.org/docs/2.2/mod/mod_proxy.html#proxypreservehost). true Enables the Host: line from an incoming request to be proxied to the host instead of hostname . false sets this option to off (default).
@@ -1349,6 +1353,10 @@ apache::vhost { 'site.name.fdqn':
13491353
`params` is an optional parameter. It allows to provide the ProxyPass key=value parameters (Connection settings).
13501354
`setenv` is optional and is an array to set environment variables for the proxy directive, for details see http://httpd.apache.org/docs/current/mod/mod_proxy.html#envsettings
13511355

1356+
#####`proxy_pass_match`
1357+
1358+
This directive is equivalent to proxy_pass, but takes regular expressions, see [ProxyPassMatch](http://httpd.apache.org/docs/current/mod/mod_proxy.html#proxypassmatch) for details.
1359+
13521360
#####`rack_base_uris`
13531361

13541362
Specifies the resource identifiers for a rack configuration. The file paths specified are listed as rack application roots for [Phusion Passenger](http://www.modrails.com/documentation/Users%20guide%20Apache.html#_railsbaseuri_and_rackbaseuri) in the _rack.erb template. Defaults to 'undef'.

manifests/vhost.pp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,10 @@
5757
$scriptalias = undef,
5858
$scriptaliases = [],
5959
$proxy_dest = undef,
60+
$proxy_dest_match = undef,
61+
$proxy_dest_reverse_match = undef,
6062
$proxy_pass = undef,
63+
$proxy_pass_match = undef,
6164
$suphp_addhandler = $::apache::params::suphp_addhandler,
6265
$suphp_engine = $::apache::params::suphp_engine,
6366
$suphp_configpath = $::apache::params::suphp_configpath,
@@ -66,6 +69,7 @@
6669
$php_admin_flags = {},
6770
$php_admin_values = {},
6871
$no_proxy_uris = [],
72+
$no_proxy_uris_match = [],
6973
$proxy_preserve_host = false,
7074
$proxy_error_override = false,
7175
$redirect_source = '/',
@@ -364,7 +368,7 @@
364368
}
365369

366370
# Load mod_proxy if needed and not yet loaded
367-
if ($proxy_dest or $proxy_pass) {
371+
if ($proxy_dest or $proxy_pass or $proxy_pass_match or $proxy_dest_match) {
368372
if ! defined(Class['apache::mod::proxy']) {
369373
include ::apache::mod::proxy
370374
}

spec/defines/vhost_spec.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,12 +215,25 @@
215215
'setenv' => ['proxy-nokeepalive 1','force-proxy-request-1.0 1'],
216216
}
217217
],
218+
'proxy_pass_match' => [
219+
{
220+
'path' => '/a',
221+
'url' => 'http://backend-a/',
222+
'keywords' => ['noquery', 'interpolate'],
223+
'params' => {
224+
'retry' => '0',
225+
'timeout' => '5'
226+
},
227+
'setenv' => ['proxy-nokeepalive 1','force-proxy-request-1.0 1'],
228+
}
229+
],
218230
'suphp_addhandler' => 'foo',
219231
'suphp_engine' => 'on',
220232
'suphp_configpath' => '/var/www/html',
221233
'php_admin_flags' => ['foo', 'bar'],
222234
'php_admin_values' => ['true', 'false'],
223235
'no_proxy_uris' => '/foo',
236+
'no_proxy_uris_match' => '/foomatch',
224237
'proxy_preserve_host' => true,
225238
'proxy_error_override' => true,
226239
'redirect_source' => '/bar',

templates/vhost/_proxy.erb

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,29 @@
3232
<%- end -%>
3333
</Location>
3434
<% end -%>
35+
<% [@proxy_pass_match].flatten.compact.each do |proxy| %>
36+
ProxyPassMatch <%= proxy['path'] %> <%= proxy['url'] %>
37+
<%- if proxy['params'] -%>
38+
<%- proxy['params'].each_pair do |key, value| -%> <%= key %>=<%= value -%>
39+
<%- end -%>
40+
<%- end -%>
41+
<%- if proxy['keywords'] %> <%= proxy['keywords'].join(' ') -%>
42+
<%- end %>
43+
<Location <%= proxy['path']%>>
44+
<%- if proxy['reverse_urls'].nil? -%>
45+
ProxyPassReverse <%= proxy['url'] %>
46+
<%- else -%>
47+
<%- Array(proxy['reverse_urls']).each do |reverse_url| -%>
48+
ProxyPassReverse <%= reverse_url %>
49+
<%- end -%>
50+
<%- end -%>
51+
<%- if proxy['setenv'] -%>
52+
<%- Array(proxy['setenv']).each do |setenv_var| -%>
53+
SetEnv <%= setenv_var -%>
54+
<%- end -%>
55+
<%- end -%>
56+
</Location>
57+
<% end -%>
3558
<% if @proxy_dest -%>
3659
<%- Array(@no_proxy_uris).each do |uri| -%>
3760
ProxyPass <%= uri %> !
@@ -41,3 +64,12 @@
4164
ProxyPassReverse <%= @proxy_dest %>/
4265
</Location>
4366
<% end -%>
67+
<% if @proxy_dest_match -%>
68+
<%- Array(@no_proxy_uris_match).each do |uri| -%>
69+
ProxyPassMatch <%= uri %> !
70+
<% end -%>
71+
ProxyPassMatch / <%= @proxy_dest_match %>/
72+
<Location />
73+
ProxyPassReverse <%= @proxy_dest_reverse_match %>/
74+
</Location>
75+
<% end -%>

0 commit comments

Comments
 (0)