Nginx proxy cache를 이용하니 이미지 캐시서버 구축이 훨씬 쉬워지네요.
https://www.wsgvet.com/web/243
여기에 정리해뒀습니다.
---
php도 필요없고 그냥 서버에 Nginx 딱 1개만 설치하면 됩니다. (SSL 인증서 발급은 먼저 하시구요)
그리고 설정파일에
[code]
proxy_cache_path /var/cache levels=1:2 keys_zone=static:100m max_size=10g inactive=30d;
proxy_cache_key "$scheme$request_method$host$request_uri";
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name cdn.example.com; # 이미지 캐시서버 도메인
server_tokens off;
location ~* \.(?:css|js|gif|png|jpg|jpeg|mp4|webm)$ {
valid_referers none blocked *.example.com example.com; # 본서버 외 불펌금지
if ($invalid_referer) {
return 403;
}
proxy_pass https://example.com; # 본서버 도메인
proxy_cache_valid 200 301 302 600m;
proxy_cache static;
proxy_cache_use_stale error timeout updating http_500 http_502 http_503 http_504;
proxy_cache_revalidate on;
proxy_cache_lock on;
proxy_ignore_headers Set-Cookie;
access_log off;
add_header My-Cache-Status $upstream_cache_status;
add_header my-ray "KR";
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
}
location / {
return 403;
}
ssl_certificate ssl/fullchain.pem; #자신의 인증서 경로로..
ssl_certificate_key ssl/privkey.pem; #자신의 인증서 경로로..
ssl_trusted_certificate ssl/chain.pem; #자신의 인증서 경로로..
ssl_stapling on;
ssl_stapling_verify on;
resolver 8.8.8.8 8.8.4.4 valid=300s;
resolver_timeout 10s;
}
[/code]
위와 같이 셋팅하고 Nginx를 재시작해줍니다.
마지막으로 본서버에 가서 캐시하고 싶은 파일들의 경로를 캐시서버 도메인으로 바꿉니다.
그러면 알아서 캐시됩니다.
정말 쉽죠?
도커로 SSL 인증서 자동화까지 합쳐서 스크립트로 만들어봐야겠네요.
댓글 8개
게시판 목록
자유게시판
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 공지 |
|
1주 전 | 10 | |
| 199478 |
|
3개월 전 | 257 | |
| 199477 |
Modify
|
3개월 전 | 257 | |
| 199476 | 3개월 전 | 277 | ||
| 199475 | 3개월 전 | 404 | ||
| 199474 | 3개월 전 | 274 | ||
| 199473 | 3개월 전 | 238 | ||
| 199472 | 3개월 전 | 578 | ||
| 199471 | 3개월 전 | 218 | ||
| 199470 | 3개월 전 | 271 | ||
| 199469 | 3개월 전 | 316 | ||
| 199468 | 3개월 전 | 318 | ||
| 199467 | 3개월 전 | 162 | ||
| 199466 | 3개월 전 | 273 | ||
| 199465 | 3개월 전 | 229 | ||
| 199464 | 3개월 전 | 221 | ||
| 199463 | 3개월 전 | 184 | ||
| 199462 | 3개월 전 | 327 | ||
| 199461 | 3개월 전 | 235 | ||
| 199460 | 3개월 전 | 352 | ||
| 199459 | 3개월 전 | 250 | ||
| 199458 | 3개월 전 | 182 | ||
| 199457 | 3개월 전 | 334 | ||
| 199456 | 3개월 전 | 294 | ||
| 199455 | 3개월 전 | 274 | ||
| 199454 |
|
3개월 전 | 198 | |
| 199453 | 3개월 전 | 333 | ||
| 199452 | 3개월 전 | 201 | ||
| 199451 | 3개월 전 | 478 | ||
| 199450 | 3개월 전 | 378 | ||
| 199449 | 3개월 전 | 304 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기