공부/기타

[nginx] 브라우저 캐시 기능 추가하기

미친사람 2016. 11. 4. 17:41
반응형

/etc/nginx/sites-enabled

 

이쪽으로 이동해서 서버 설정 파일오픈

 

 

location ~* \.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc)$ {

 expires 1M; #한달

 access_log off;

 add_header Cache-Control "public";

 }



 location ~* \.(?:css|js)$ {

 expires 1y; #일년

 access_log off;

 add_header Cache-Control "public";

 }

 

이걸 자기 서버단쪽에 추가

 

 

예시

 

server {

server_name 서버도메인;

root /home/서버폴더/public_html;

include xe.conf;

index index.html index.htm index.php;

    location ~ \.php$ {

        limit_req zone=limit burst=5 nodelay;

        fastcgi_pass   127.0.0.1:9000;

        fastcgi_index  index.php;

        fastcgi_param   SCRIPT_FILENAME /home/서버폴더/public_html$fastcgi_script_name;

        include fastcgi_params;

    }



 location ~* \.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc)$ {

 expires 1M;

 access_log off;

 add_header Cache-Control "public";

 }



 location ~* \.(?:css|js)$ {

 expires 1y;

 access_log off;

 add_header Cache-Control "public";

 }

}

 

 

반응형