1313### installing the site) and update.php: all updates are now
1414### handled through drush.
1515
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+
1623## The 'default' location.
1724location / {
1825
@@ -33,7 +40,7 @@ location / {
3340
3441 { %- if nginx_drupal_php_handling == 'proxy' %}
3542 ## Proxy configuration
36- proxy_pass http ://phpapache/index .php?q=$uri ;
43+ proxy_pass http ://phpapache/index .php?q={{ _nginx_drupal_uri }} ;
3744 proxy_set_header Connection '' ;
3845 { %- endif -%}
3946
@@ -59,7 +66,7 @@ location / {
5966
6067 { %- if nginx_drupal_php_handling == 'proxy' %}
6168 ## Proxy configuration
62- proxy_pass http ://phpapache/index .php?q=$uri ;
69+ proxy_pass http ://phpapache/index .php?q={{ _nginx_drupal_uri }} ;
6370 proxy_set_header Connection '' ;
6471 { % endif %}
6572
@@ -80,7 +87,7 @@ location / {
8087
8188 access_log off;
8289 expires 30d ;
83- try_files $uri @drupal;
90+ try_files {{ _nginx_drupal_uri }} @drupal;
8491 }
8592
8693 ## Drupal 7 generated image handling, i.e., imagecache in core. See:
@@ -93,7 +100,7 @@ location / {
93100
94101 access_log off;
95102 expires 30d ;
96- try_files $uri @drupal;
103+ try_files {{ _nginx_drupal_uri }} @drupal;
97104 }
98105
99106 ## Advanced Aggregation module CSS
@@ -106,38 +113,43 @@ location / {
106113
107114 location ~ * /sites/default/files/advagg_css/css[_[:alnum:]]+\.css$ {
108115 access_log off;
109- try_files $uri @drupal;
116+ try_files {{ _nginx_drupal_uri }} @drupal;
110117 }
111118 }
112119
113120 ## Advanced Aggregation module JS
114121 ## support. http://drupal.org/project/advagg.
115122 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 %}
116127 expires max;
117128 add_header ETag '' ;
118129 add_header Last-Modified 'Wed, 20 Jan 1988 04:20:42 GMT' ;
130+ { % endif %}
119131 add_header Accept-Ranges '' ;
120132
121133 location ~ * /sites/default/files/advagg_js/js[_[:alnum:]]+\.js$ {
122134 access_log off;
123- try_files $uri @drupal;
135+ try_files {{ _nginx_drupal_uri }} @drupal;
124136 }
125137 }
126138
127139 { % if nginx_drupal_language_path_prefixes %}
128140 ## RSS feed support.
129141 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;
131143 }
132144
133145 ## XML Sitemap support.
134146 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;
136148 }
137149
138150 ## Core search support.
139151 location ~ * ^( ?:\/(?:{{ nginx_drupal_language_path_prefixes|join('|') }}))?\/search/.+/.+ {
140- try_files $uri @drupal-no-args;
152+ try_files {{ _nginx_drupal_uri }} @drupal-no-args;
141153 }
142154 { % endif %}
143155
@@ -158,7 +170,7 @@ location / {
158170
159171 ## Core search support.
160172 location ~ * ^/search/.+/.+ {
161- try_files $uri @drupal-no-args;
173+ try_files {{ _nginx_drupal_uri }} @drupal-no-args;
162174 }
163175
164176 ## PDFs and powerpoint files handling.
@@ -240,7 +252,7 @@ location / {
240252
241253 { %- if nginx_drupal_php_handling == 'proxy' %}
242254 ## Proxy configuration
243- proxy_pass http ://phpapache/index .php?q=$uri ;
255+ proxy_pass http ://phpapache/index .php?q={{ _nginx_drupal_uri }} ;
244256 proxy_set_header Connection '' ;
245257 { %- endif -%}
246258 }
@@ -253,9 +265,55 @@ location / {
253265 return 404 ;
254266 }
255267
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 %}
256272 ## 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;
258315}
316+ { % endif %}
259317
260318########### Security measures ##########
261319
@@ -286,7 +344,7 @@ location @drupal {
286344
287345 { %- if nginx_drupal_php_handling == 'proxy' %}
288346 ## Proxy configutation
289- proxy_pass http ://phpapache/index .php?q=$uri ;
347+ proxy_pass http ://phpapache/index .php?q={{ _nginx_drupal_uri }} ;
290348 proxy_set_header Connection '' ;
291349 { %- if nginx_drupal_microcache %}
292350 ## Proxy microcache.
@@ -325,7 +383,7 @@ location @drupal-no-args {
325383
326384 { %- if nginx_drupal_php_handling == 'proxy' %}
327385 ## Proxy configutation
328- proxy_pass http ://phpapache/index .php?q=$uri ;
386+ proxy_pass http ://phpapache/index .php?q={{ _nginx_drupal_uri }} ;
329387 proxy_set_header Connection '' ;
330388
331389 { %- if nginx_drupal_microcache %}
@@ -377,17 +435,17 @@ location = /robots.txt {
377435 access_log off;
378436 ## Add support for the robotstxt module
379437 ## http://drupal.org/project/robotstxt.
380- try_files $uri @drupal-no-args;
438+ try_files {{ _nginx_drupal_uri }} @drupal-no-args;
381439}
382440
383441## RSS feed support.
384442location = /rss.xml {
385- try_files $uri @drupal-no-args;
443+ try_files {{ _nginx_drupal_uri }} @drupal-no-args;
386444}
387445
388446## XML Sitemap support.
389447location = /sitemap.xml {
390- try_files $uri @drupal-no-args;
448+ try_files {{ _nginx_drupal_uri }} @drupal-no-args;
391449}
392450
393451## Support for favicon. Return an 1x1 transparent GIF if it doesn't
@@ -412,3 +470,17 @@ location ~* ^.+\.php$ {
412470location = /monitor/index .php {
413471 fastcgi_pass phpcgi;
414472}
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