13
13
#
14
14
###################################################################################################
15
15
16
-
17
- # Add header to HTML cached files
18
- location ~ /wp-content/cache/wp-rocket/.*html$ {
19
- add_header Vary "Accept-Encoding, Cookie";
20
- }
21
-
22
- # Do not gzip cached files that are already zipped
23
- location ~ /wp-content/cache/wp-rocket/.*_gzip$ {
24
- gzip off;
25
- types {}
26
- default_type text/html;
27
- add_header Content-Encoding gzip;
28
- add_header Vary "Accept-Encoding, Cookie";
29
- }
30
-
16
+ set $rocket_debug 0; # Add debug information into header
31
17
32
18
set $rocket_bypass 1; # Should NGINX bypass WordPress and call cache file directly ?
33
19
set $rocket_encryption ""; # Is GZIP accepted by client ?
34
20
set $rocket_file ""; # Filename to use
35
21
set $rocket_is_bypassed "No"; # Header text added to check if the bypass worked or not. Header: X-Rocket-Nginx-Bypass
36
- set $rocket_reason ""; #
22
+ set $rocket_reason ""; # Reason why cache file was not used. If cache file is used, what file was used
23
+
37
24
38
25
# Is GZIP accepted by client ?
39
26
if ($http_accept_encoding ~ gzip) {
40
- set $rocket_gzip "_gzip";
27
+ set $rocket_encryption "_gzip";
41
28
}
42
29
43
30
# File to return IF we must bypass WordPress
44
- set $rocket_file $document_root/wp-content/cache/wp-rocket/$http_host/$request_uri/index.html$rocket_encryption;
31
+ set $rocket_url "/wp-content/cache/wp-rocket/$http_host/$request_uri/index.html$rocket_encryption";
32
+ set $rocket_file "$document_root$rocket_url";
45
33
46
34
47
35
# Do not bypass if it's a POST request
@@ -74,14 +62,39 @@ if (!-f "$rocket_file") {
74
62
set $rocket_reason "File not cached";
75
63
}
76
64
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
+
77
71
# If the bypass token is still on, rewrite according to the file linked to the request
78
72
if ($rocket_bypass = 1) {
79
73
set $rocket_is_bypassed "Yes";
80
- rewrite ^(.*)$ "$rocket_file" last;
74
+ set $rocket_reason "$rocket_url";
75
+ rewrite .* "$rocket_url" last;
81
76
}
82
77
83
- # Did our NGINX configuration bypassed WordPress ?
84
- add_header X-Rocket-Nginx-Bypass $rocket_is_bypassed;
78
+ # Clear variables if debug is not needed
79
+ if ($rocket_debug = 0) {
80
+ set $rocket_is_bypassed "";
81
+ set $rocket_reason "";
82
+ }
85
83
86
- # If not, what is the reason for not serving a cache file directly
87
- add_header X-Rocket-Nginx-Reason $rocket_reason;
84
+ # Add header to HTML cached files
85
+ location ~ /wp-content/cache/wp-rocket/.*html$ {
86
+ add_header Vary "Accept-Encoding, Cookie";
87
+ add_header X-Rocket-Nginx-Bypass $rocket_is_bypassed;
88
+ add_header X-Rocket-Nginx-Reason $rocket_reason;
89
+ }
90
+
91
+ # Do not gzip cached files that are already gzipped
92
+ location ~ /wp-content/cache/wp-rocket/.*_gzip$ {
93
+ gzip off;
94
+ types {}
95
+ default_type text/html;
96
+ add_header Content-Encoding gzip;
97
+ add_header Vary "Accept-Encoding, Cookie";
98
+ add_header X-Rocket-Nginx-Bypass $rocket_is_bypassed;
99
+ add_header X-Rocket-Nginx-Reason $rocket_reason;
100
+ }
0 commit comments