Skip to content

Commit 7bc417b

Browse files
author
Pierre Paul Lefebvre
committed
Adding custom locations with basic support for denied/allowed IPs
1 parent e3a9a38 commit 7bc417b

File tree

2 files changed

+57
-1
lines changed

2 files changed

+57
-1
lines changed

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,13 @@ The following variables are available to configure the role:
104104
- **regex**: The regular expression used to match the URI.
105105
- **replacement**: The replacement pattern used for the rewrite.
106106
- **flags**: (optional) The flag parameter for the rewrite.
107+
- **custom_locations**: (optional) A list of locations directives, using the
108+
following structure:
109+
- **operator**: (optional) Operator to match the location path (defaults to '=')
110+
- **path**: Path string to match on
111+
- **allowed_ips**: (optional) List of IP (with or without subnet) allowed to visit this location
112+
- **denied_ips**: (optional) List of IP (with or without subnet) denied to visit this location
113+
- **fastcgi_pass**: (optional) fastcgi socket (or IP) to send to. If not specified, will use the @drupal location as upstream.
107114
- **includes**: (optional) A list of additional Nginx configuration files
108115
to include for the site.
109116
- **server_name_in_redirect**: (optional) Enables or disables the use of
@@ -174,4 +181,4 @@ Apache v2
174181
Author Information
175182
------------------
176183

177-
Pierre Buyle <buyle@pheromone.ca>
184+
Pierre Buyle <buyle@pheromone.ca>

templates/sites-available/drupal-site.j2

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,30 @@ server {
7878
{% endfor %}
7979
{% endif %}
8080

81+
{% if item.custom_locations is defined -%}
82+
## Custom location(s)
83+
{% for location in item.custom_locations -%}
84+
location {{ location.operator|default('=') }} "{{ location.path }}" {
85+
{% if location.allowed_ips is defined -%}
86+
{% for allowed_ip in location.allowed_ips %}
87+
allow {{ allowed_ip }};
88+
{% endfor %}
89+
deny all;
90+
{% endif %}
91+
{%- if location.denied_ips is defined -%}
92+
{%- for denied_ip in location.denied_ips %}
93+
deny {{ denied_ip }};
94+
{% endfor %}
95+
{% endif -%}
96+
{%- if location.fastcgi_pass is defined -%}
97+
include fastcgi_params;
98+
fastcgi_pass {{ location.fastcgi_pass }};
99+
{% else %}
100+
try_files $uri @drupal;
101+
{% endif %}
102+
}
103+
{% endfor %}
104+
{% endif %}
81105

82106
{% if not nginx_drupal_use_boost -%}
83107
{% if not nginx_drupal_escape_uri -%}
@@ -267,6 +291,31 @@ server {
267291
{% endfor %}
268292
{% endif %}
269293

294+
{% if item.custom_locations is defined %}
295+
## Custom location(s)
296+
{% for location in item.custom_locations %}
297+
location {{ location.operator }} "{{ location.path }}" {
298+
{% if location.allowed_ips is defined %}
299+
{% for allowed_ip in location.allowed_ips %}
300+
allow {{ allowed_ip }};
301+
{% endfor %}
302+
deny all;
303+
{% endif %}
304+
{% if location.denied_ips is defined %}
305+
{% for denied_ip in location.denied_ips %}
306+
deny {{ denied_ip }};
307+
{% endfor %}
308+
{% endif %}
309+
{% if location.fastcgi_pass is defined %}
310+
include fastcgi_params;
311+
fastcgi_pass {{ location.fastcgi_pass }};
312+
{% else %}
313+
try_files $uri @drupal;
314+
{% endif %}
315+
}
316+
{% endfor %}
317+
{% endif %}
318+
270319
{% if not nginx_drupal_use_boost -%}
271320
{% if not nginx_drupal_escape_uri -%}
272321
################################################################

0 commit comments

Comments
 (0)