Commit 8bd1fafd authored by omega8cc's avatar omega8cc

Nginx: Use $status in fastcgi_cache_key

This prevents caching/sharing errors and 403 responses for all anonymous visitors when custom fastcgi_cache_valid is forced via header('X-Accel-Expires: 300'); etc.
parent e6b33d13
......@@ -1019,6 +1019,7 @@ location ~ ^/(?<esi>esi/.*)"$ {
add_header X-GeoIP-Country-Name "$geoip_country_name";
add_header X-This-Proto "$http_x_forwarded_proto";
add_header X-Server-Name "$main_site_name";
add_header X-Response-Status "$status";
add_header Cache-Control "no-store, no-cache, must-revalidate, post-check=0, pre-check=0";
###
### Set correct, local $uri.
......@@ -1042,7 +1043,7 @@ location ~ ^/(?<esi>esi/.*)"$ {
fastcgi_cache speed;
fastcgi_cache_methods GET HEAD;
fastcgi_cache_min_uses 1;
fastcgi_cache_key "$is_bot$device$host$request_method$uri$is_args$args$cache_uid$http_x_forwarded_proto";
fastcgi_cache_key "$is_bot$device$host$request_method$uri$is_args$args$cache_uid$http_x_forwarded_proto$status";
fastcgi_cache_valid 200 301 404 5s;
fastcgi_cache_valid 302 1m;
fastcgi_ignore_headers Cache-Control Expires;
......@@ -1172,6 +1173,7 @@ location = /index.php {
add_header X-NoCache "$nocache_details";
add_header X-This-Proto "$http_x_forwarded_proto";
add_header X-Server-Name "$main_site_name";
add_header X-Response-Status "$status";
<?php endif; ?>
add_header Cache-Control "no-store, no-cache, must-revalidate, post-check=0, pre-check=0";
tcp_nopush off;
......@@ -1197,7 +1199,7 @@ location = /index.php {
fastcgi_cache speed;
fastcgi_cache_methods GET HEAD; ### Nginx default, but added for clarity
fastcgi_cache_min_uses 1;
fastcgi_cache_key "$is_bot$device$host$request_method$key_uri$cache_uid$http_x_forwarded_proto$sent_http_x_local_proto$cookie_respimg";
fastcgi_cache_key "$is_bot$device$host$request_method$key_uri$cache_uid$http_x_forwarded_proto$sent_http_x_local_proto$cookie_respimg$status";
fastcgi_cache_valid 200 10s;
fastcgi_cache_valid 302 1m;
fastcgi_cache_valid 301 403 404 5s;
......
......@@ -974,6 +974,7 @@ location ^~ /<?php print $subdir; ?> {
add_header X-NoCache "$nocache_details";
add_header X-This-Proto "$http_x_forwarded_proto";
add_header X-Server-Sub-Name "$subdir_main_site_name";
add_header X-Response-Status "$status";
<?php endif; ?>
root <?php print "{$this->root}"; ?>;
......@@ -1023,7 +1024,7 @@ location ^~ /<?php print $subdir; ?> {
fastcgi_cache speed;
fastcgi_cache_methods GET HEAD; ### Nginx default, but added for clarity
fastcgi_cache_min_uses 1;
fastcgi_cache_key "$is_bot$device$host$request_method$key_uri$cache_uid$http_x_forwarded_proto$sent_http_x_local_proto$cookie_respimg";
fastcgi_cache_key "$is_bot$device$host$request_method$key_uri$cache_uid$http_x_forwarded_proto$sent_http_x_local_proto$cookie_respimg$status";
fastcgi_cache_valid 200 10s;
fastcgi_cache_valid 302 1m;
fastcgi_cache_valid 301 403 404 5s;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment