Skip to content

Commit c8157c6

Browse files
committed
Added debug, fixed bugs
1 parent 926719a commit c8157c6

File tree

1 file changed

+36
-23
lines changed

1 file changed

+36
-23
lines changed

rocket-nginx.conf

Lines changed: 36 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,35 +13,23 @@
1313
#
1414
###################################################################################################
1515

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
3117

3218
set $rocket_bypass 1; # Should NGINX bypass WordPress and call cache file directly ?
3319
set $rocket_encryption ""; # Is GZIP accepted by client ?
3420
set $rocket_file ""; # Filename to use
3521
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+
3724

3825
# Is GZIP accepted by client ?
3926
if ($http_accept_encoding ~ gzip) {
40-
set $rocket_gzip "_gzip";
27+
set $rocket_encryption "_gzip";
4128
}
4229

4330
# 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";
4533

4634

4735
# Do not bypass if it's a POST request
@@ -74,14 +62,39 @@ if (!-f "$rocket_file") {
7462
set $rocket_reason "File not cached";
7563
}
7664

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+
7771
# If the bypass token is still on, rewrite according to the file linked to the request
7872
if ($rocket_bypass = 1) {
7973
set $rocket_is_bypassed "Yes";
80-
rewrite ^(.*)$ "$rocket_file" last;
74+
set $rocket_reason "$rocket_url";
75+
rewrite .* "$rocket_url" last;
8176
}
8277

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+
}
8583

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

Comments
 (0)