7
7
# Author: Maxime Jobin
8
8
# URL: https://github.com/maximejobin/rocket-nginx
9
9
#
10
- # Tested with WP-Rocket version: 2.6.9
10
+ # Tested with WP-Rocket version: 2.6.15
11
11
# Tested with NGINX: 1.8.0 (stable)
12
12
#
13
- # Version 1.0. 1
13
+ # Version 1.1
14
14
#
15
15
###################################################################################################
16
16
17
17
set $rocket_debug 0; # Add debug information into header
18
+ set $rocket_hsts_value ""; # HTTP Strict Transport Security (if you want overwrite default)
18
19
19
20
###################################################################################################
20
21
# Do not alter theses values
@@ -24,8 +25,11 @@ set $rocket_encryption ""; # Is GZIP accepted by client ?
24
25
set $rocket_file ""; # Filename to use
25
26
set $rocket_is_bypassed "No"; # Header text added to check if the bypass worked or not. Header: X-Rocket-Nginx-Bypass
26
27
set $rocket_reason ""; # Reason why cache file was not used. If cache file is used, what file was used
27
- set $https_prefix ""; # HTTPS prefix to use when cached files are using HTTPS
28
+ set $rocket_https_prefix ""; # HTTPS prefix to use when cached files are using HTTPS
29
+ set $rocket_hsts 0; # Is HSTS is off (0) by default. Will be turned on (1) if request is HTTPS
28
30
31
+ # HSTS Default value : 1 year, include subdomains.
32
+ set $rocket_hsts_value_default "max-age=31536000; includeSubDomains";
29
33
30
34
###################################################################################################
31
35
# PAGE CACHE
@@ -38,11 +42,22 @@ if ($http_accept_encoding ~ gzip) {
38
42
39
43
# Is SSL request ?
40
44
if ($https = "on") {
41
- set $https_prefix "-https";
45
+ set $rocket_https_prefix "-https";
46
+ set $rocket_hsts 1;
47
+ }
48
+
49
+ # If HSTS value is not set, use default value
50
+ if ($rocket_hsts_value = "") {
51
+ set $rocket_hsts_value "$rocket_hsts_value_default";
52
+ }
53
+
54
+ # If HSTS is disabled, unset HSTS set for Rocket-Nginx configuration
55
+ if ($rocket_hsts = "0") {
56
+ set $rocket_hsts_value "";
42
57
}
43
58
44
59
# File/URL to return IF we must bypass WordPress
45
- set $rocket_url "/wp-content/cache/wp-rocket/$http_host/$request_uri/index$https_prefix .html$rocket_encryption";
60
+ set $rocket_url "/wp-content/cache/wp-rocket/$http_host/$request_uri/index$rocket_https_prefix .html$rocket_encryption";
46
61
set $rocket_file "$document_root$rocket_url";
47
62
48
63
@@ -101,6 +116,7 @@ location ~ /wp-content/cache/wp-rocket/.*html$ {
101
116
add_header X-Rocket-Nginx-Bypass $rocket_is_bypassed;
102
117
add_header X-Rocket-Nginx-Reason $rocket_reason;
103
118
add_header X-Rocket-Nginx-File $rocket_file;
119
+ add_header Strict-Transport-Security "$rocket_hsts_value";
104
120
expires 30d;
105
121
}
106
122
@@ -114,6 +130,7 @@ location ~ /wp-content/cache/wp-rocket/.*_gzip$ {
114
130
add_header X-Rocket-Nginx-Bypass $rocket_is_bypassed;
115
131
add_header X-Rocket-Nginx-Reason $rocket_reason;
116
132
add_header X-Rocket-Nginx-File $rocket_file;
133
+ add_header Strict-Transport-Security "$rocket_hsts_value";
117
134
expires 30d;
118
135
}
119
136
@@ -122,6 +139,8 @@ add_header X-Rocket-Nginx-Bypass $rocket_is_bypassed;
122
139
add_header X-Rocket-Nginx-Reason $rocket_reason;
123
140
add_header X-Rocket-Nginx-File $rocket_file;
124
141
142
+ # No HSTS header added here. We suppose it's correctly added in the site configuration
143
+
125
144
126
145
###################################################################################################
127
146
# BROWSER CSS CACHE
0 commit comments