13
13
### installing the site) and update.php: all updates are now
14
14
### handled through drush.
15
15
16
+ {% if nginx_drupal_escape_uri %}
17
+ ## To avoid the ugly rewrite we use Lua to escape the URI.
18
+ set_by_lua $escaped_uri 'return ngx.escape_uri(ngx.var.uri)' ;
19
+ {% endif %}
20
+
21
+ {% set _nginx_drupal_uri = '$escaped_uri ' if nginx_drupal_escape_uri else '$uri ' %}
22
+
16
23
## The 'default' location.
17
24
location / {
18
25
@@ -33,7 +40,7 @@ location / {
33
40
34
41
{%- if nginx_drupal_php_handling == 'proxy' %}
35
42
## Proxy configuration
36
- proxy_pass http://phpapache/index.php?q=$uri ;
43
+ proxy_pass http://phpapache/index.php?q={{_nginx_drupal_uri}} ;
37
44
proxy_set_header Connection '' ;
38
45
{%- endif -%}
39
46
@@ -59,7 +66,7 @@ location / {
59
66
60
67
{%- if nginx_drupal_php_handling == 'proxy' %}
61
68
## Proxy configuration
62
- proxy_pass http://phpapache/index.php?q=$uri ;
69
+ proxy_pass http://phpapache/index.php?q={{_nginx_drupal_uri}} ;
63
70
proxy_set_header Connection '' ;
64
71
{% endif %}
65
72
@@ -80,7 +87,7 @@ location / {
80
87
81
88
access_log off ;
82
89
expires 30d ;
83
- try_files $uri @drupal;
90
+ try_files {{_nginx_drupal_uri}} @drupal;
84
91
}
85
92
86
93
## Drupal 7 generated image handling, i.e., imagecache in core. See:
@@ -93,7 +100,7 @@ location / {
93
100
94
101
access_log off ;
95
102
expires 30d ;
96
- try_files $uri @drupal;
103
+ try_files {{_nginx_drupal_uri}} @drupal;
97
104
}
98
105
99
106
## Advanced Aggregation module CSS
@@ -106,38 +113,43 @@ location / {
106
113
107
114
location ~* /sites/default/files/advagg_css/css[_[:alnum:]]+\.css$ {
108
115
access_log off ;
109
- try_files $uri @drupal;
116
+ try_files {{_nginx_drupal_uri}} @drupal;
110
117
}
111
118
}
112
119
113
120
## Advanced Aggregation module JS
114
121
## support. http://drupal.org/project/advagg.
115
122
location ^~ /sites/default/files/advagg_js/ {
123
+ {% if nginx_drupal_use_boost %}
124
+ add_header Pragma '' ;
125
+ add_header Cache-Control 'public, max-age=946080000' ;
126
+ {% else %}
116
127
expires max ;
117
128
add_header ETag '' ;
118
129
add_header Last-Modified 'Wed, 20 Jan 1988 04:20:42 GMT' ;
130
+ {% endif %}
119
131
add_header Accept-Ranges '' ;
120
132
121
133
location ~* /sites/default/files/advagg_js/js[_[:alnum:]]+\.js$ {
122
134
access_log off ;
123
- try_files $uri @drupal;
135
+ try_files {{_nginx_drupal_uri}} @drupal;
124
136
}
125
137
}
126
138
127
139
{% if nginx_drupal_language_path_prefixes %}
128
140
## RSS feed support.
129
141
location ~* ^(?:\/(?: {{ nginx_drupal_language_path_prefixes|join('|') }}))?\/rss\.xml$ {
130
- try_files $uri @drupal-no-args;
142
+ try_files {{_nginx_drupal_uri}} @drupal-no-args;
131
143
}
132
144
133
145
## XML Sitemap support.
134
146
location ~* ^(?:\/(?: {{ nginx_drupal_language_path_prefixes|join('|') }}))?\/sitemap\.xml$ {
135
- try_files $uri @drupal-no-args;
147
+ try_files {{_nginx_drupal_uri}} @drupal-no-args;
136
148
}
137
149
138
150
## Core search support.
139
151
location ~* ^(?:\/(?: {{ nginx_drupal_language_path_prefixes|join('|') }}))?\/search/.+/.+ {
140
- try_files $uri @drupal-no-args;
152
+ try_files {{_nginx_drupal_uri}} @drupal-no-args;
141
153
}
142
154
{% endif %}
143
155
@@ -158,7 +170,7 @@ location / {
158
170
159
171
## Core search support.
160
172
location ~* ^/search/.+/.+ {
161
- try_files $uri @drupal-no-args;
173
+ try_files {{_nginx_drupal_uri}} @drupal-no-args;
162
174
}
163
175
164
176
## PDFs and powerpoint files handling.
@@ -240,7 +252,7 @@ location / {
240
252
241
253
{%- if nginx_drupal_php_handling == 'proxy' %}
242
254
## Proxy configuration
243
- proxy_pass http://phpapache/index.php?q=$uri ;
255
+ proxy_pass http://phpapache/index.php?q={{_nginx_drupal_uri}} ;
244
256
proxy_set_header Connection '' ;
245
257
{%- endif -%}
246
258
}
@@ -253,9 +265,55 @@ location / {
253
265
return 404 ;
254
266
}
255
267
268
+ {% if nginx_drupal_use_boost %}
269
+ ## First we try the URI and relay to the @cache if not found.
270
+ try_files {{_nginx_drupal_uri}} @cache;
271
+ {% else %}
256
272
## First we try the URI and relay to the /index.php?q=$uri&$args if not found.
257
- try_files $uri @drupal;
273
+ try_files {{_nginx_drupal_uri}} @drupal;
274
+ {% endif %}
275
+ }
276
+
277
+ {% if nginx_drupal_use_boost %}
278
+ ## We define a named location for the cache.
279
+ location @cache {
280
+ ## Boost compresses can the pages so we check it. Comment it out
281
+ ## if you don't have it enabled in Boost.
282
+ gzip_static on ;
283
+
284
+ ## Error page handler for the case where $no_cache is 1. POST
285
+ ## request or authenticated.
286
+ error_page 418 = @drupal;
287
+
288
+ ## If $no_cache is 1 then it means that either we have a session
289
+ ## cookie or that the request method is POST. So serve the dynamic
290
+ ## page.
291
+ if ($no_cache ) {
292
+ return 418 ; # I'm a teapot/I can't get no cachifaction
293
+ }
294
+
295
+ ## No caching for POST requests.
296
+ if ($request_method = POST) {
297
+ return 418 ;
298
+ }
299
+
300
+ # Now for some header tweaking. We use a date that differs
301
+ # from stock Drupal. Everyone seems to be using their
302
+ # birthdate. Why go against the grain?
303
+ add_header Expires "Tue, 13 Jun 1977 03:45:00 GMT" ;
304
+ # We bypass all delays in the post-check and pre-check
305
+ # parameters of Cache-Control. Both set to 0.
306
+ add_header Cache-Control "must-revalidate, post-check=0, pre-check=0" ;
307
+ # Funny...perhaps. Egocentric? Damn right!;
308
+ add_header X-Header "Boost Helás Avril 1.0" ;
309
+ ## Boost doesn't set a charset.
310
+ charset utf-8;
311
+
312
+ # We try each boost URI in succession, if every one of them
313
+ # fails then relay to Drupal.
314
+ try_files /cache/normal/$host ${uri}_${args}.html /cache/perm/$host ${uri}_.css /cache/perm/$host ${uri}_.js /cache/$host /0$uri .html /cache/$host /0${uri}/index.html @drupal;
258
315
}
316
+ {% endif %}
259
317
260
318
########### Security measures ##########
261
319
@@ -286,7 +344,7 @@ location @drupal {
286
344
287
345
{%- if nginx_drupal_php_handling == 'proxy' %}
288
346
## Proxy configutation
289
- proxy_pass http://phpapache/index.php?q=$uri ;
347
+ proxy_pass http://phpapache/index.php?q={{_nginx_drupal_uri}} ;
290
348
proxy_set_header Connection '' ;
291
349
{%- if nginx_drupal_microcache %}
292
350
## Proxy microcache.
@@ -325,7 +383,7 @@ location @drupal-no-args {
325
383
326
384
{%- if nginx_drupal_php_handling == 'proxy' %}
327
385
## Proxy configutation
328
- proxy_pass http://phpapache/index.php?q=$uri ;
386
+ proxy_pass http://phpapache/index.php?q={{_nginx_drupal_uri}} ;
329
387
proxy_set_header Connection '' ;
330
388
331
389
{%- if nginx_drupal_microcache %}
@@ -377,17 +435,17 @@ location = /robots.txt {
377
435
access_log off ;
378
436
## Add support for the robotstxt module
379
437
## http://drupal.org/project/robotstxt.
380
- try_files $uri @drupal-no-args;
438
+ try_files {{_nginx_drupal_uri}} @drupal-no-args;
381
439
}
382
440
383
441
## RSS feed support.
384
442
location = /rss.xml {
385
- try_files $uri @drupal-no-args;
443
+ try_files {{_nginx_drupal_uri}} @drupal-no-args;
386
444
}
387
445
388
446
## XML Sitemap support.
389
447
location = /sitemap.xml {
390
- try_files $uri @drupal-no-args;
448
+ try_files {{_nginx_drupal_uri}} @drupal-no-args;
391
449
}
392
450
393
451
## Support for favicon. Return an 1x1 transparent GIF if it doesn't
@@ -412,3 +470,17 @@ location ~* ^.+\.php$ {
412
470
location = /monitor/index.php {
413
471
fastcgi_pass phpcgi;
414
472
}
473
+
474
+ {% if nginx_drupal_use_boost %}
475
+ ## Boost stats.
476
+ location = /boost_stats.php {
477
+ {%- if nginx_drupal_php_handling == 'php-fpm' or nginx_drupal_php_handling == 'php-cgi' %}
478
+ fastcgi_pass phpcgi;
479
+ {% endif %}
480
+
481
+ {%- if nginx_drupal_php_handling == 'proxy' %}
482
+ ## Proxy configuration
483
+ proxy_pass http://phpapache
484
+ {% endif %}
485
+ }
486
+ {% endif %}
0 commit comments