Send HTTP header Vary: Cookie to prevent localization cache bug

Fixes #477
This commit is contained in:
wiz 2021-04-27 18:58:46 +09:00
parent 24b7acdc60
commit 0d03a9e6cc
No known key found for this signature in database
GPG Key ID: A394E332255A6173
2 changed files with 8 additions and 2 deletions

View File

@ -7,10 +7,11 @@
# fallback for all URLs i.e. /address/foo /tx/foo /block/000 # fallback for all URLs i.e. /address/foo /tx/foo /block/000
location / { location / {
add_header Vary Cookie;
try_files /$lang/$uri /$lang/$uri/ $uri $uri/ /en-US/$uri @index-redirect; try_files /$lang/$uri /$lang/$uri/ $uri $uri/ /en-US/$uri @index-redirect;
} }
location @index-redirect { location @index-redirect {
add_header vary accept-language; add_header Vary Cookie;
rewrite (.*) /$lang/index.html; rewrite (.*) /$lang/index.html;
} }
@ -18,10 +19,12 @@
# used to rewrite resources from /<lang>/ to /en-US/ # used to rewrite resources from /<lang>/ to /en-US/
location ~ ^/(ar|bg|bs|ca|cs|da|de|et|el|es|eo|eu|fa|fr|gl|ko|hr|id|it|he|ka|lv|lt|hu|mk|ms|nl|ja|ka|no|nb|nn|pl|pt|pt-BR|ro|ru|sk|sl|sr|sh|fi|sv|th|tr|uk|vi|zh)/resources/ { location ~ ^/(ar|bg|bs|ca|cs|da|de|et|el|es|eo|eu|fa|fr|gl|ko|hr|id|it|he|ka|lv|lt|hu|mk|ms|nl|ja|ka|no|nb|nn|pl|pt|pt-BR|ro|ru|sk|sl|sr|sh|fi|sv|th|tr|uk|vi|zh)/resources/ {
add_header Vary Cookie;
rewrite ^/[a-zA-Z-]*/resources/(.*) /en-US/resources/$1; rewrite ^/[a-zA-Z-]*/resources/(.*) /en-US/resources/$1;
} }
# used for cookie override # used for cookie override
location ~ ^/(ar|bg|bs|ca|cs|da|de|et|el|es|eo|eu|fa|fr|gl|ko|hr|id|it|he|ka|lv|lt|hu|mk|ms|nl|ja|ka|no|nb|nn|pl|pt|pt-BR|ro|ru|sk|sl|sr|sh|fi|sv|th|tr|uk|vi|zh)/ { location ~ ^/(ar|bg|bs|ca|cs|da|de|et|el|es|eo|eu|fa|fr|gl|ko|hr|id|it|he|ka|lv|lt|hu|mk|ms|nl|ja|ka|no|nb|nn|pl|pt|pt-BR|ro|ru|sk|sl|sr|sh|fi|sv|th|tr|uk|vi|zh)/ {
add_header Vary Cookie;
try_files $uri $uri/ /$1/index.html =404; try_files $uri $uri/ /$1/index.html =404;
} }

View File

@ -35,15 +35,17 @@
location / { location / {
try_files /$lang/$uri /$lang/$uri/ $uri $uri/ /en-US/$uri @index-redirect; try_files /$lang/$uri /$lang/$uri/ $uri $uri/ /en-US/$uri @index-redirect;
add_header Cache-Control "public, no-transform"; add_header Cache-Control "public, no-transform";
add_header Vary Cookie;
expires 10m; expires 10m;
} }
location /resources { location /resources {
try_files /$lang/$uri /$lang/$uri/ $uri $uri/ /en-US/$uri @index-redirect; try_files /$lang/$uri /$lang/$uri/ $uri $uri/ /en-US/$uri @index-redirect;
add_header Cache-Control "public, no-transform"; add_header Cache-Control "public, no-transform";
add_header Vary Cookie;
expires 1h; expires 1h;
} }
location @index-redirect { location @index-redirect {
add_header vary accept-language; add_header Vary Cookie;
rewrite (.*) /$lang/index.html; rewrite (.*) /$lang/index.html;
} }
@ -55,6 +57,7 @@
} }
# used for cookie override # used for cookie override
location ~ ^/(ar|bg|bs|ca|cs|da|de|et|el|es|eo|eu|fa|fr|gl|ko|hr|id|it|he|ka|lv|lt|hu|mk|ms|nl|ja|ka|no|nb|nn|pl|pt|pt-BR|ro|ru|sk|sl|sr|sh|fi|sv|th|tr|uk|vi|zh)/ { location ~ ^/(ar|bg|bs|ca|cs|da|de|et|el|es|eo|eu|fa|fr|gl|ko|hr|id|it|he|ka|lv|lt|hu|mk|ms|nl|ja|ka|no|nb|nn|pl|pt|pt-BR|ro|ru|sk|sl|sr|sh|fi|sv|th|tr|uk|vi|zh)/ {
add_header Vary Cookie;
try_files $uri $uri/ /$1/index.html =404; try_files $uri $uri/ /$1/index.html =404;
} }