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개
게시판 목록
자유게시판
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 199447 | 2개월 전 | 269 | ||
| 199446 | 2개월 전 | 250 | ||
| 199445 | 2개월 전 | 236 | ||
| 199444 |
비버팩토리
|
2개월 전 | 209 | |
| 199443 | 2개월 전 | 501 | ||
| 199442 | 2개월 전 | 303 | ||
| 199441 | 2개월 전 | 419 | ||
| 199440 | 2개월 전 | 294 | ||
| 199439 | 2개월 전 | 275 | ||
| 199438 |
|
2개월 전 | 486 | |
| 199437 | 2개월 전 | 184 | ||
| 199436 | 2개월 전 | 193 | ||
| 199435 | 2개월 전 | 295 | ||
| 199434 | 2개월 전 | 234 | ||
| 199433 | 2개월 전 | 266 | ||
| 199432 | 2개월 전 | 220 | ||
| 199431 | 2개월 전 | 367 | ||
| 199430 | 2개월 전 | 278 | ||
| 199429 | 2개월 전 | 416 | ||
| 199428 | 2개월 전 | 279 | ||
| 199427 | 2개월 전 | 235 | ||
| 199426 |
|
2개월 전 | 266 | |
| 199425 |
techstar
|
2개월 전 | 267 | |
| 199424 | 2개월 전 | 225 | ||
| 199423 | 2개월 전 | 262 | ||
| 199422 | 2개월 전 | 395 | ||
| 199421 | 2개월 전 | 221 | ||
| 199420 | 2개월 전 | 382 | ||
| 199419 | 2개월 전 | 289 | ||
| 199418 | 2개월 전 | 272 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기