본문 바로가기
Server/Nginx

프록시 통해서 전달되는 svg 파일도 gzip 압축하여 전송 설정

by web data 2024. 6. 6.

프록시 설정을 하면, 이를 통해서 전송되는 컨텐츠는 content-type 이 "application/octet-stream" 로 전송됨으로 인해 svg 파일이 압축되지 않고 전달된다.

 

이를 처리하기 위해서는 아래와 같이 설정한다.

 

1. /etc/nginx/nginx.conf 에 설정 추가
http {

	##
	# Basic Settings
	##
        .
        .
        .


	##
	# Gzip Settings
	##

	gzip on;

	gzip_vary on;
	gzip_proxied any;
	gzip_comp_level 6;
	gzip_buffers 16 8k;
	gzip_http_version 1.1;
	gzip_types text/plain 
		   text/css 
		   application/json 
		   application/javascript 
		   text/xml 
		   application/xml 
		   application/xml+rss 
		   text/javascript 
		   image/svg+xml;



        # 이부분 추가
        map $uri $custom_content_type {
                default           application/octet-stream;
                ~(.*.svg)$        image/svg+xml;
        }		   

        .
        .
        .
	
}

* 위와 같이 기존 gzip 설정 아래 쪽에 map 부분을 설정해준다.

 

2. /etc/nginx/sites-available/default  의 프록시 설정부분에 아래 설정 추가 
server {
        listen 8080 default_server;
        listen [::]:80 default_server;
        
        .
        .
        .
        
        
        location ^~ /api {
                proxy_pass http://localhost:9150;
                proxy_http_version 1.1;
                proxy_set_header Host $host;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_hide_header Content-Type;
                add_header Content-Type $custom_content_type;
                charset utf-8;
        }
        
        
}

* 기존 프록시 항목에 proxy_hide_header, add_header 항목을 추가한다.

 

nginx restart

 

service nginx restart

 

 

'Server > Nginx' 카테고리의 다른 글

nginx CORS 처리  (0) 2025.02.26
nginx cache 설정하기  (2) 2024.11.13
nginx 파일 업로드 최대 용량 제한  (0) 2024.06.06
nginx proxy 설정  (0) 2024.06.06
nginx gzip 설정 (웹사이트 컨텐츠 압축하여 전송)  (0) 2024.06.06