Skip to content

Commit

Permalink
Allow to set ProxyPassReverse attributes on a vhost
Browse files Browse the repository at this point in the history
This commit allows you to add an array or a string as a proxy_pass['reverse_url']
parameter.

Useful when used with mod_balancer.
  • Loading branch information
roidelapluie committed Aug 7, 2014
1 parent 62dac65 commit 231832e
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -991,10 +991,14 @@ apache::vhost { 'site.name.fdqn':
{ 'path' => '/a', 'url' => 'http://backend-a/' },
{ 'path' => '/b', 'url' => 'http://backend-b/' },
{ 'path' => '/c', 'url' => 'http://backend-a/c' },
{ 'path' => '/l', 'url' => 'http://backend-xy',
'reverse_urls' => ['http://backend-x', 'http://backend-y'] },
],
}
```

`reverse_urls` is optional and can be an array or a string. It is useful when used with `mod_proxy_balancer`.

#####`rack_base_uris`

Specifies the resource identifiers for a rack configuration. The file paths specified will be 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'.
Expand Down
27 changes: 27 additions & 0 deletions spec/defines/vhost_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,33 @@
],
:notmatch => [/ProxyPass .+!$/],
},
{
:title => 'should accept reverse_urls string',
:attr => 'proxy_pass',
:value => { 'path' => '/path-a', 'url' => 'http://fake.com/a', 'reverse_urls' => 'http://127.0.0.1:8080' },
:match => [
/^ ProxyPass \/path-a http:\/\/fake.com\/a$/,
/^ <Location \/path-a>$/,
/^ ProxyPassReverse http:\/\/127.0.0.1:8080$/,
/^ <\/Location>$/,

],
:notmatch => [/^ ProxyPassReverse http:\/\/fake.com\/a$/],
},
{
:title => 'should accept reverse_urls array',
:attr => 'proxy_pass',
:value => { 'path' => '/path-a', 'url' => 'http://fake.com/a', 'reverse_urls' => ['http://127.0.0.1:8080', 'http://127.0.0.1:8081'] },
:match => [
/^ ProxyPass \/path-a http:\/\/fake.com\/a$/,
/^ <Location \/path-a>$/,
/^ ProxyPassReverse http:\/\/127.0.0.1:8080$/,
/^ ProxyPassReverse http:\/\/127.0.0.1:8081$/,
/^ <\/Location>$/,

],
:notmatch => [/^ ProxyPassReverse http:\/\/fake.com\/a$/],
},
{
:title => 'should accept proxy_pass array of hash',
:attr => 'proxy_pass',
Expand Down
6 changes: 6 additions & 0 deletions templates/vhost/_proxy.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@
<%- [@proxy_pass].flatten.compact.each do |proxy| -%>
ProxyPass <%= proxy['path'] %> <%= proxy['url'] %>
<Location <%= proxy['path']%>>
<%- if proxy['reverse_urls'].nil? -%>
ProxyPassReverse <%= proxy['url'] %>
<%- else -%>
<%- Array(proxy['reverse_urls']).each do |reverse_url| -%>
ProxyPassReverse <%= reverse_url %>
<%- end -%>
<%- end -%>
</Location>
<% end %>
<% if @proxy_dest -%>
Expand Down

0 comments on commit 231832e

Please sign in to comment.