nginx

ngx_http_gzip_static_module

꺼비72 2024. 5. 6. 13:41
반응형

On-the-fly 압축을 하지 않고 사전에 압축된 파일을 전송하는 방법

https://nginx.org/en/docs/http/ngx_http_gzip_static_module.html 

 

Module ngx_http_gzip_static_module

Module ngx_http_gzip_static_module The ngx_http_gzip_static_module module allows sending precompressed files with the “.gz” filename extension instead of regular files. This module is not built by default, it should be enabled with the --with-http_gzip

nginx.org

gzip의 경우 위 모듈을 설치해야하고

brotli의 경우 https://github.com/google/ngx_brotli 에 포함됨

 

 

1) static파일 전송 기능이 없을 경우

.gz나 .bz파일이 없을 경우 해더는 gzip으로 On-the-fly로 압축되지만 Conents size가 나타나지 않음

# curl -I org/1.json  -H "accept-encoding: gzip" -I
HTTP/1.1 200 OK
Server: nginx
Date: Mon, 06 May 2024 04:45:42 GMT
Content-Type: application/json
Last-Modified: Mon, 06 May 2024 04:25:31 GMT
Connection: keep-alive
Vary: Accept-Encoding
ETag: W/"66385bbb-1100"
Cache-Control: max-age=120
X-Test: aaa
Content-Encoding: gzip

 

이 경우 size해더가 없어 range요청도 되지 않음

# curl -I org/1.json  -H "accept-encoding: gzip" -I -H "range: bytes=0-10"
HTTP/1.1 200 OK
Server: nginx
Date: Mon, 06 May 2024 04:47:38 GMT
Content-Type: application/json
Last-Modified: Mon, 06 May 2024 04:25:31 GMT
Connection: keep-alive
Vary: Accept-Encoding
ETag: W/"66385bbb-1100"
Cache-Control: max-age=120
X-Test: aaa
Content-Encoding: gzip

 

2) static 전송기능이 있을 경우

 

nginx 에서 아래와 같이 설정하고, 압축이 필요한 파일을 미리 압축해서 원본 서버 구성

gzip_static on;

brotli_static on;

 

gzip은 .gz확장자로, brotli는 .bz확장자로 사전압축해 동일한 위치에 두어야함

 

Accept-Ranges 해더와 Content-Length해더가 나타나고 range요청도 가능

# curl -I org/1.json  -H "accept-encoding: gzip" -I
HTTP/1.1 200 OK
Server: nginx
Date: Mon, 06 May 2024 04:50:33 GMT
Content-Type: application/json
Content-Length: 109
Last-Modified: Tue, 30 Apr 2024 08:20:26 GMT
Connection: keep-alive
Vary: Accept-Encoding
ETag: "6630a9ca-6d"
Content-Encoding: gzip
Cache-Control: max-age=120
X-Test: aaa
Accept-Ranges: bytes
# curl -I org/1.json  -H "accept-encoding: gzip" -I -H "range: bytes=0-10"
HTTP/1.1 206 Partial Content
Server: nginx
Date: Mon, 06 May 2024 04:50:36 GMT
Content-Type: application/json
Content-Length: 11
Last-Modified: Tue, 30 Apr 2024 08:20:26 GMT
Connection: keep-alive
Vary: Accept-Encoding
ETag: "6630a9ca-6d"
Content-Encoding: gzip
Cache-Control: max-age=120
X-Test: aaa
Content-Range: bytes 0-10/109

 

3) gzip과 br을 동시에 enable했을 때 br이 우선이나, static on을 키면 static해서 줄 수 있는 Contents가 있는 압축방식이 우선함 (gzip은 static 파일이 있고, brotli는 없는 경우 gzip이 우선)

# curl -I org/1.json  -H "accept-encoding: gzip, br" -I
HTTP/1.1 200 OK
Server: nginx
Date: Mon, 06 May 2024 05:24:51 GMT
Content-Type: application/json
Content-Length: 109
Last-Modified: Tue, 30 Apr 2024 08:20:26 GMT
Connection: keep-alive
Vary: Accept-Encoding
ETag: "6630a9ca-6d"
Content-Encoding: gzip
Cache-Control: max-age=120
X-Test: aaa
Accept-Ranges: bytes

'nginx' 카테고리의 다른 글

ngx_brotli  (0) 2024.05.06
chunked_transfer_encoding  (0) 2024.04.29
원본 압축관련 최종 nginx proxy설정  (0) 2024.04.29
gzip 최대 압축지원  (0) 2024.04.29
압축을 지원하지 않는 원본일 경우 Proxy에서 압축  (0) 2024.04.29