Skip to content

Commit ac9d1b9

Browse files
author
Pierre Paul Lefebvre
committed
Merge with master
2 parents 0a28715 + 63f7bcc commit ac9d1b9

File tree

5 files changed

+95
-20
lines changed

5 files changed

+95
-20
lines changed

README.md

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -61,37 +61,54 @@ The following variables are available to configure the role:
6161
(cf. http://wiki.nginx.org/HttpFlvStreamModule), defaults to false.
6262
- **nginx_drupal_mp4_streaming**: Whether or not to use MP4 streaming, (cf.
6363
http://nginx.org/en/docs/http/ngx_http_mp4_module.html) defaults to false.
64-
- **nginx_drupal_http_pre_includes**: A list of file to include in the ```http```
65-
context (in ```nginx.conf```), before any other directives.
66-
- **nginx_drupal_http_post_includes**: A list of file to include in the ```http```
67-
context (in ```nginx.conf```), after any other directives except the enabled
64+
- **nginx_drupal_http_pre_includes**: A list of file to include in the
65+
```http``` context (in ```nginx.conf```), before any other directives.
66+
- **nginx_drupal_http_post_includes**: A list of file to include in the
67+
```http``` context (in ```nginx.conf```), after any other directives except
68+
the enabled
6869
site configuration files.
69-
- **nginx_drupal_upstream_servers**: The list of PHP upstream servers, each item
70-
is a server address (and parameters, see
70+
- **nginx_drupal_upstream_servers**: The list of PHP upstream servers, each
71+
item is a server address (and parameters, see
7172
http://nginx.org/en/docs/http/ngx_http_upstream_module.html#server), defaults
7273
to ```["unix:/var/run/php-fpm.sock", "php-fpm-zwei.sock"]```.
7374
- **nginx_drupal_upstream_backup_servers**: The list of PHP upstream backup
7475
servers, defaults to ```["unix:/var/run/php-fpm-bkp.sock"]```.
76+
- **nginx_drupal_language_path_prefixes**: (optional) The list of enabled
77+
language path prefixes used on the site.
78+
- **nginx_drupal_x_frame_options**: (optional) Value of the X-Frame-Options
79+
response header, defaults to `DENY`. If the site uses frames, set to
80+
`SAMEORIGIN`. `DENY` may conflicts with pseudo streaming (at least with Nginx
81+
version 1.0.12)
7582
- **nginx_drupal_sites**: The list of available sites.
7683
Each site uses the following structure:
7784
- **file_name**: The name of the site configuration file.
7885
- **http**: HTTP server configuration (leave empty to disable HTTP)
7986
- **port**: The port to listen on
8087
- **https**: HTTPS server configuration (leave empty to disable HTTPS)
81-
- **port**: The port to listen on
82-
- **certificate**: Path to the SSL certificate of the server (in the PEM
83-
format).
88+
- **port**: The port to listen on.
89+
- **certificate**: Path to the SSL certificate of the server (in the
90+
PEM format).
8491
- **certificate_key**: Path to the SSL secret key of the server (in the
8592
PEM format).
8693
- **server_name**: The (primary) server name.
8794
- **ipv6**: (optional) IPv6 address of the server
88-
- **alternate_server_name**: (optional) Alternate server name, configured as
89-
redirect to the primary server site. This can be used to remove the
95+
- **alternate_server_name**: (optional) Alternate server name, configured
96+
as redirect to the primary server site. This can be used to remove the
9097
```www.``` prefix.
9198
- **root**: Path to the root directory for the site.
9299
- **limit_conn**: (optional) The limit_conn for the site (defaults to
93100
```arbeit 32```).
94101
- **enabled**: Whether or not the site should be enabled (defaults to true).
102+
- **rewrites**: (optional) A list of rewrites directives, using the
103+
following structure:
104+
- **regex**: The regular expression used to match the URI.
105+
- **replacement**: The replacement pattern used for the rewrite.
106+
- **flags**: (optional) The flag parameter for the rewrite.
107+
- **includes**: (optional) A list of additional Nginx configuration files
108+
to include for the site.
109+
- **server_name_in_redirect**: (optional) Enables or disables the use of
110+
the primary server name, specified by the server_name directive, in
111+
redirects issued by nginx.
95112

96113

97114
Examples
@@ -125,8 +142,8 @@ HTTPS but disabled.
125142
certificate: /etc/nginx/ssl/bar.cert
126143
certificate_key: /etc/nginx/ssl/bar.key
127144

128-
Nginx as a Reverse Proxy for a single Drupal 6 sites, without microcaching and
129-
with image hot linking protection.
145+
Nginx as a Reverse Proxy for a single Drupal 6 sites, without microcaching,
146+
with image hot linking protection and a rewrite directive.
130147

131148

132149
- hosts: all
@@ -144,6 +161,10 @@ with image hot linking protection.
144161
root: /var/www/foo
145162
http:
146163
port: 80
164+
rewrites:
165+
- regex: '^/foo-bar.htm$'
166+
replacement: '/foo/bar'
167+
flags: 'permanent'
147168

148169
License
149170
-------

defaults/main.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,5 @@ nginx_drupal_upstream_backup_servers: ["unix:/var/run/php-fpm-bkp.sock"]
3030
nginx_drupal_sites: none
3131
nginx_drupal_http_pre_includes: []
3232
nginx_drupal_http_post_includes: []
33+
nginx_drupal_language_path_prefixes: []
34+
nginx_drupal_x_frame_options: DENY

templates/apps/drupal/drupal.j2

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,18 @@ location / {
124124
}
125125
}
126126

127+
{% if nginx_drupal_language_path_prefixes %}
128+
## RSS feed support.
129+
location ~* ^(?:\/(?:{{ nginx_drupal_language_path_prefixes|join('|') }}))?\/rss\.xml$ {
130+
try_files $uri @drupal-no-args;
131+
}
132+
133+
## XML Sitemap support.
134+
location ~* ^(?:\/(?:{{ nginx_drupal_language_path_prefixes|join('|') }}))?\/sitemap\.xml$ {
135+
try_files $uri @drupal-no-args;
136+
}
137+
{% endif %}
138+
127139
## All static files will be served directly.
128140
location ~* ^.+\.(?:css|cur|js|jpe?g|gif|htc|ico|png|html|xml|otf|ttf|eot|woff|svg)$ {
129141

@@ -386,3 +398,7 @@ location ~* ^.+\.php$ {
386398
return 404;
387399
}
388400

401+
## Add support for custom monitoring script.
402+
location = /monitor/index.php {
403+
fastcgi_pass phpcgi;
404+
}

templates/nginx.j2

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -162,16 +162,13 @@ http {
162162
## https://www.owasp.org/index.php/List_of_useful_HTTP_headers.
163163
add_header X-XSS-Protection '1; mode=block';
164164

165+
{% if nginx_drupal_x_frame_options %}
165166
## Enable clickjacking protection in modern browsers. Available in
166167
## IE8 also. See
167168
## https://developer.mozilla.org/en/The_X-FRAME-OPTIONS_response_header
168169
## This may conflicts with pseudo streaming (at least with Nginx version 1.0.12).
169-
## Uncomment the line below if you're not using media streaming.
170-
## For sites being framing on the same domqin uncomment the line below.
171-
#add_header X-Frame-Options SAMEORIGIN;
172-
## For sites accepting to be framed in any context comment the
173-
## line below.
174-
add_header X-Frame-Options DENY;
170+
add_header X-Frame-Options {{ nginx_drupal_x_frame_options }};
171+
{% endif %}
175172

176173
## Block MIME type sniffing on IE.
177174
add_header X-Content-Options nosniff;
@@ -213,10 +210,12 @@ http {
213210
## Include the Nginx stub status allowed hosts configuration block.
214211
include nginx_status_allowed_hosts.conf;
215212

213+
{%- if not nginx_drupal_use_drush %}
216214
## If you want to run cron using Drupal cron.php. i.e., you're not
217215
## using drush then uncomment the line below. Specify in
218216
## cron_allowed_hosts.conf which hosts can invole cron.
219-
# include apps/drupal/cron_allowed_hosts.conf;
217+
include apps/drupal/cron_allowed_hosts.conf;
218+
{%- endif -%}
220219

221220
## Include blacklist for bad bot and referer blocking.
222221
include blacklist.conf;

templates/sites-available/drupal-site.j2

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ server {
2525
{% endif %}
2626

2727
server_name {{item.server_name}};
28+
{% if item.limit_conn != 'None' %}
2829
limit_conn {{item.limit_conn|default('arbeit 32')}};
30+
{% endif %}
2931

3032
## Access and error logs.
3133
access_log {{nginx_drupal_log_path}}/{{item.server_name}}_{{item.file_name}}_access.log;
@@ -60,6 +62,23 @@ server {
6062
proxy_http_version 1.1; # keep alive to the Apache upstream
6163
{% endif %}
6264

65+
server_name_in_redirect {{'on' if item.server_name_in_redirect|default(false) else 'off'}};
66+
67+
{% if item.rewrites is defined %}
68+
## URL rewriting
69+
{% for rewrite in item.rewrites %}
70+
rewrite {{rewrite.regex}} {{rewrite.replacement}} {{rewrite.flags|default('')}};
71+
{% endfor %}
72+
{%- endif %}
73+
74+
{% if item.includes is defined %}
75+
## Custom include(s)
76+
{% for include in item.includes %}
77+
include {{ include }};
78+
{% endfor %}
79+
{% endif %}
80+
81+
6382
{% if not nginx_drupal_use_boost -%}
6483
{% if not nginx_drupal_escape_uri -%}
6584
################################################################
@@ -183,7 +202,9 @@ server {
183202

184203
server_name {{item.server_name}};
185204

205+
{% if item.limit_conn != 'None' %}
186206
limit_conn {{item.limit_conn|default('arbeit 32')}};
207+
{% endif %}
187208

188209
## Access and error logs.
189210
access_log {{nginx_drupal_log_path}}/{{item.server_name}}_access.log;
@@ -230,6 +251,22 @@ server {
230251
return 405;
231252
}
232253

254+
server_name_in_redirect {{'on' if item.server_name_in_redirect|default(false) else 'off'}};
255+
256+
{% if item.rewrites is defined %}
257+
## URL rewriting
258+
{% for rewrite in item.rewrites %}
259+
rewrite {{rewrite.regex}} {{rewrite.replacement}} {{rewrite.flags|default('')}};
260+
{% endfor %}
261+
{%- endif %}
262+
263+
{% if item.includes is defined %}
264+
## Custom include(s)
265+
{% for include in item.includes %}
266+
include {{ include }};
267+
{% endfor %}
268+
{% endif %}
269+
233270
{% if not nginx_drupal_use_boost -%}
234271
{% if not nginx_drupal_escape_uri -%}
235272
################################################################

0 commit comments

Comments
 (0)