文章摘要:cdn部署nginx如何配置 nginx cdn配置
使用nginx部署cdn的方法如下: upstream backend { server& […]
使用nginx部署cdn的方法如下:
upstream backend {
server 1.1.1.1;
keepalive 128;
}
proxy_temp_path /dev/shm;
proxy_cache_path /data/nginx/cache levels=1:2 keys_zone=cache_one:500m inactive=10d max_size=1024m;
limit_conn_zone $binary_remote_addr zone=addr:20m;
limit_req_zone $binary_remote_addr zone=req_addr:20m rate=200r/s;
server{
listen 80 ;
server_name www.iquduo.com;
access_log logs/e.cn.access.log main;
error_log logs/e.cn.error.log;
location ~* .(aac|mp3|mp4|jpeg|jpg|png|gif|js|htm|html|css|avi|mpg|rar|wmv|doc|docx|mov|flv|pdf|edb|ppt|pptx)$ {
root /data/nginx/cache;
proxy_cache_use_stale error timeout http_500 http_502 http_503 http_504;
proxy_cache cache_one;
proxy_cache_valid 200 206 304 12h;
proxy_cache_revalidate on;
add_header X-Cache $upstream_cache_status;
add_header Via "CDN";
#limit_rate_after 4096k;
#limit_rate 2048k;
#limit_req zone=req_addr burst=300 nodelay;
#limit_req_status 503;
#proxy_limit_rate 256000; #64000 = 1Mb per connections
proxy_cache_key $scheme$proxy_host$uri;
proxy_cache_lock on;
proxy_cache_lock_timeout 10s;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://backend;
proxy_http_version 1.1;
proxy_set_header Connection "";
}
location ~ / {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://backend;
proxy_http_version 1.1;
proxy_set_header Connection "";
}
}