7
7
# Author: Maxime Jobin
8
8
# URL: https://github.com/maximejobin/rocket-nginx
9
9
#
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)
11
12
#
12
- # Version 0.1
13
+ # Version 0.2
13
14
#
14
15
###################################################################################################
15
16
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
17
27
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
23
28
29
+ ###################################################################################################
30
+ # PAGE CACHE
31
+ #
24
32
25
33
# Is GZIP accepted by client ?
26
34
if ($http_accept_encoding ~ gzip) {
27
35
set $rocket_encryption "_gzip";
28
36
}
29
37
30
- # File to return IF we must bypass WordPress
38
+ # File/URL to return IF we must bypass WordPress
31
39
set $rocket_url "/wp-content/cache/wp-rocket/$http_host/$request_uri/index.html$rocket_encryption";
32
40
set $rocket_file "$document_root$rocket_url";
33
41
@@ -51,7 +59,9 @@ if (-f "$document_root/.maintenance") {
51
59
}
52
60
53
61
# 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_)") {
55
65
set $rocket_bypass 0;
56
66
set $rocket_reason "Cookie";
57
67
}
@@ -62,12 +72,6 @@ if (!-f "$rocket_file") {
62
72
set $rocket_reason "File not cached";
63
73
}
64
74
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
-
71
75
# If the bypass token is still on, rewrite according to the file linked to the request
72
76
if ($rocket_bypass = 1) {
73
77
set $rocket_is_bypassed "Yes";
@@ -97,4 +101,30 @@ location ~ /wp-content/cache/wp-rocket/.*_gzip$ {
97
101
add_header Vary "Accept-Encoding, Cookie";
98
102
add_header X-Rocket-Nginx-Bypass $rocket_is_bypassed;
99
103
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