Skip to content

Commit aee814d

Browse files
committed
Merge pull request #17 from dmajorel/boost_support
Boost support
2 parents 0625176 + ed4197d commit aee814d

File tree

3 files changed

+91
-71
lines changed

3 files changed

+91
-71
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ The following variables are available to configure the role:
3434
- **nginx_drupal_php_handling**: The PHP handling method, one of "php-fpm",
3535
"php-cgi" or "proxy", defaults to "php-fpm".
3636
- **nginx_drupal_escape_uri**: Whether or not to escaped URIs, defaults to
37-
false. **No implemented**
37+
false.
3838
- **nginx_drupal_use_boost**: Whether or not [Boost](http://drupal.org/project/boost)
39-
is used, defaults to false. **No implemented**
39+
is used, defaults to false.
4040
- **nginx_drupal_use_drush**: Whether or not [Drush](https://github.com/drush-ops/drush)
4141
is used, defaults to true.
4242
- **nginx_drupal_allow_install**: Whether or not to allow access to the

templates/apps/drupal/drupal.j2

+89-17
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@
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.
1724
location / {
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.
384442
location = /rss.xml {
385-
try_files $uri @drupal-no-args;
443+
try_files {{_nginx_drupal_uri}} @drupal-no-args;
386444
}
387445

388446
## XML Sitemap support.
389447
location = /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$ {
412470
location = /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 %}

templates/sites-available/drupal-site.j2

-52
Original file line numberDiff line numberDiff line change
@@ -106,33 +106,7 @@ server {
106106
{% endfor %}
107107
{% endif %}
108108
109-
{% if not nginx_drupal_use_boost -%}
110-
{% if not nginx_drupal_escape_uri -%}
111-
################################################################
112-
### Generic configuration: for most Drupal 7 sites.
113-
################################################################
114109
include apps/drupal/drupal.conf;
115-
{% else %}
116-
################################################################
117-
### Configuration for Drupal 7 sites to serve URIs that need
118-
### to be **escaped**
119-
################################################################
120-
include apps/drupal/drupal_escaped.conf;
121-
{%- endif -%}
122-
{%- else %}
123-
{%- if not nginx_drupal_escape_uri %}
124-
#################################################################
125-
### Configuration for Drupal 7 sites that use boost.
126-
#################################################################
127-
include apps/drupal/drupal_boost.conf;
128-
{%- else %}
129-
#################################################################
130-
### Configuration for Drupal 7 sites that use boost if having
131-
### to serve URIs that need to be **escaped**
132-
#################################################################
133-
include apps/drupal/drupal_boost_escaped.conf;
134-
{%- endif -%}
135-
{%- endif -%}
136110
137111
{%- if not nginx_drupal_use_drush %}
138112
#################################################################
@@ -322,33 +296,7 @@ server {
322296
{% endfor %}
323297
{% endif %}
324298
325-
{% if not nginx_drupal_use_boost -%}
326-
{% if not nginx_drupal_escape_uri -%}
327-
################################################################
328-
### Generic configuration: for most Drupal 7 sites.
329-
################################################################
330299
include apps/drupal/drupal.conf;
331-
{% else %}
332-
################################################################
333-
### Configuration for Drupal 7 sites to serve URIs that need
334-
### to be **escaped**
335-
################################################################
336-
include apps/drupal/drupal_escaped.conf;
337-
{%- endif -%}
338-
{%- else %}
339-
{%- if not nginx_drupal_escape_uri %}
340-
#################################################################
341-
### Configuration for Drupal 7 sites that use boost.
342-
#################################################################
343-
include apps/drupal/drupal_boost.conf;
344-
{%- else %}
345-
#################################################################
346-
### Configuration for Drupal 7 sites that use boost if having
347-
### to serve URIs that need to be **escaped**
348-
#################################################################
349-
include apps/drupal/drupal_boost_escaped.conf;
350-
{%- endif -%}
351-
{%- endif -%}
352300
353301
{%- if not nginx_drupal_use_drush %}
354302
#################################################################

0 commit comments

Comments
 (0)