Skip to content

Commit b7b8fd0

Browse files
committed
Added browser cache and fixed bugs and typos
1 parent c8157c6 commit b7b8fd0

File tree

1 file changed

+47
-17
lines changed

1 file changed

+47
-17
lines changed

rocket-nginx.conf

Lines changed: 47 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,35 @@
77
# Author: Maxime Jobin
88
# URL: https://github.com/maximejobin/rocket-nginx
99
#
10-
# Tested with WP-Rocket version: 2.3.9
10+
# Tested with WP-Rocket version: 2.3.10
11+
# Tested with NGINX: 1.6.2 (stable)
1112
#
12-
# Version 0.1
13+
# Version 0.2
1314
#
1415
###################################################################################################
1516

16-
set $rocket_debug 0; # Add debug information into header
17+
set $rocket_debug 0; # Add debug information into header
18+
19+
###################################################################################################
20+
# Do not alter theses values
21+
#
22+
set $rocket_bypass 1; # Should NGINX bypass WordPress and call cache file directly ?
23+
set $rocket_encryption ""; # Is GZIP accepted by client ?
24+
set $rocket_file ""; # Filename to use
25+
set $rocket_is_bypassed "No"; # Header text added to check if the bypass worked or not. Header: X-Rocket-Nginx-Bypass
26+
set $rocket_reason ""; # Reason why cache file was not used. If cache file is used, what file was used
1727

18-
set $rocket_bypass 1; # Should NGINX bypass WordPress and call cache file directly ?
19-
set $rocket_encryption ""; # Is GZIP accepted by client ?
20-
set $rocket_file ""; # Filename to use
21-
set $rocket_is_bypassed "No"; # Header text added to check if the bypass worked or not. Header: X-Rocket-Nginx-Bypass
22-
set $rocket_reason ""; # Reason why cache file was not used. If cache file is used, what file was used
2328

29+
###################################################################################################
30+
# PAGE CACHE
31+
#
2432

2533
# Is GZIP accepted by client ?
2634
if ($http_accept_encoding ~ gzip) {
2735
set $rocket_encryption "_gzip";
2836
}
2937

30-
# File to return IF we must bypass WordPress
38+
# File/URL to return IF we must bypass WordPress
3139
set $rocket_url "/wp-content/cache/wp-rocket/$http_host/$request_uri/index.html$rocket_encryption";
3240
set $rocket_file "$document_root$rocket_url";
3341

@@ -51,7 +59,9 @@ if (-f "$document_root/.maintenance") {
5159
}
5260

5361
# Do not bypass if one of those cookie if found
54-
if ($http_cookie ~* "(comment_author|wordpress_logged_in|wp\-postpass)") {
62+
# wordpress_logged_in_[hash] : When a user is logged in, this cookie is created (we'd rather let WP-Rocket handle that)
63+
# wp-postpass_[hash] : When a protected pass requires a password, this cookie is created.
64+
if ($http_cookie ~* "(wordpress_logged_in_|wp\-postpass_)") {
5565
set $rocket_bypass 0;
5666
set $rocket_reason "Cookie";
5767
}
@@ -62,12 +72,6 @@ if (!-f "$rocket_file") {
6272
set $rocket_reason "File not cached";
6373
}
6474

65-
# Did our NGINX configuration bypassed WordPress ?
66-
add_header X-Rocket-Nginx-Bypass $rocket_is_bypassed;
67-
68-
# If not, what is the reason for not serving a cache file directly
69-
add_header X-Rocket-Nginx-Reason $rocket_reason;
70-
7175
# If the bypass token is still on, rewrite according to the file linked to the request
7276
if ($rocket_bypass = 1) {
7377
set $rocket_is_bypassed "Yes";
@@ -97,4 +101,30 @@ location ~ /wp-content/cache/wp-rocket/.*_gzip$ {
97101
add_header Vary "Accept-Encoding, Cookie";
98102
add_header X-Rocket-Nginx-Bypass $rocket_is_bypassed;
99103
add_header X-Rocket-Nginx-Reason $rocket_reason;
100-
}
104+
}
105+
106+
107+
###################################################################################################
108+
# BROWSER CSS CACHE
109+
#
110+
location ~ /wp-content/cache/min/.*\.css$ {
111+
add_header Vary "Accept-Encoding";
112+
expires 30d;
113+
}
114+
115+
116+
###################################################################################################
117+
# BROWSER JS CACHE
118+
#
119+
location ~ /wp-content/cache/min/.*\.js$ {
120+
add_header Vary "Accept-Encoding";
121+
expires 30d;
122+
}
123+
124+
125+
###################################################################################################
126+
# BROWSER IMAGES CACHE
127+
#
128+
location ~* \.(ico|gif|jpe?g|png)$ {
129+
expires 30d;
130+
}

0 commit comments

Comments
 (0)