반응형
아래설정으로 Accept-Encoding이 없을 경우 gzip으로 원본으로 요청하고 원본응답 저장
if ($http_accept_encoding ~ br) { set $encoding "br, gzip"; break; }
if ($http_accept_encoding ~ gzip) { set $encoding "gzip"; break; }
if ($http_accept_encoding = "") { set $encoding "gzip"; break; }
proxy_ignore_headers Vary ;
proxy_cache_key $host$uri$is_args$args$encoding;
gunzip on;
proxy_set_header Accept-Encoding "$encoding";
(테스트) relay로 raw 요청 시 gunzip으로 풀어서 응답 (cache된 파일은 gzip으로 응답옴)
# curl org/1.json -I
HTTP/1.1 200 OK
Server: nginx/1.25.4
Date: Sat, 27 Apr 2024 17:16:27 GMT
Content-Type: application/json
Content-Length: 4346
Last-Modified: Wed, 21 Feb 2024 06:27:24 GMT
Connection: keep-alive
Vary: Accept-Encoding
ETag: "65d597cc-10fa"
Cache-Control: max-age=120
Accept-Ranges: bytes
# curl relay/1.json -I
HTTP/1.1 200 OK
Server: nginx/1.25.4
Date: Sat, 27 Apr 2024 17:16:33 GMT
Content-Type: application/json
Connection: keep-alive
Last-Modified: Wed, 21 Feb 2024 06:27:24 GMT
Vary: Accept-Encoding
ETag: W/"65d597cc-10fa"
Cache-Control: max-age=120
X-CACHE-STATUS: MISS
# head -n 15 /var/cache/nginx/3/1a/88e8b9e64fbc7833d180cdb7a6e251a3
i3-f̗▒e▒2-fSʪ▒g▒W/"65d597cc-10fa"
KEY: relay/1.jsongzip
HTTP/1.1 200 OK
Server: nginx/1.25.4
Date: Sat, 27 Apr 2024 17:16:33 GMT
Content-Type: application/json
Last-Modified: Wed, 21 Feb 2024 06:27:24 GMT
Transfer-Encoding: chunked
Connection: keep-alive
Vary: Accept-Encoding
ETag: W/"65d597cc-10fa"
Cache-Control: max-age=120
Content-Encoding: gzip
'nginx' 카테고리의 다른 글
gzip 최대 압축지원 (0) | 2024.04.29 |
---|---|
압축을 지원하지 않는 원본일 경우 Proxy에서 압축 (0) | 2024.04.29 |
accept-encoding nomalization (0) | 2024.04.29 |
nginx gzip, brotli (ngx_gzip, ngx_brotli) 설정 (0) | 2024.04.29 |
How to purge the Nginx cache (0) | 2023.06.19 |