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 | |
| 199388 |
|
3개월 전 | 275 | |
| 199387 | 3개월 전 | 274 | ||
| 199386 | 3개월 전 | 336 | ||
| 199385 |
|
3개월 전 | 330 | |
| 199384 | 3개월 전 | 243 | ||
| 199383 | 3개월 전 | 288 | ||
| 199382 | 3개월 전 | 284 | ||
| 199381 |
|
3개월 전 | 301 | |
| 199380 |
노마드액션
|
3개월 전 | 257 | |
| 199379 | 3개월 전 | 237 | ||
| 199378 |
|
3개월 전 | 297 | |
| 199377 | 3개월 전 | 299 | ||
| 199376 | 3개월 전 | 292 | ||
| 199375 |
|
3개월 전 | 303 | |
| 199374 | 3개월 전 | 288 | ||
| 199373 | 3개월 전 | 254 | ||
| 199372 | 3개월 전 | 228 | ||
| 199371 | 3개월 전 | 419 | ||
| 199370 | 3개월 전 | 288 | ||
| 199369 | 3개월 전 | 313 | ||
| 199368 | 3개월 전 | 326 | ||
| 199367 |
|
3개월 전 | 199 | |
| 199366 | 3개월 전 | 283 | ||
| 199365 | 3개월 전 | 376 | ||
| 199364 | 3개월 전 | 584 | ||
| 199363 |
|
3개월 전 | 492 | |
| 199362 | 3개월 전 | 361 | ||
| 199361 | 3개월 전 | 297 | ||
| 199360 |
|
3개월 전 | 447 | |
| 199359 | 3개월 전 | 349 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기