时间:2022-12-06 01:18
使用nginx部署cdn的方法如下:
upstreambackend{server1.1.1.1;
keepalive128;
}
proxy_temp_path/dev/shm;
proxy_cache_path/data/nginx/cachelevels=1:2keys_zone=cache_one:500minactive=10dmax_size=1024m;
limit_conn_zone$binary_remote_addrzone=addr:20m;
limit_req_zone$binary_remote_addrzone=req_addr:20mrate=200r/s;
server{
listen80;
server_namewww.iquduo.com;
access_loglogs/e.cn.access.logmain;
error_loglogs/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_staleerrortimeouthttp_500http_502http_503http_504;
proxy_cachecache_one;
proxy_cache_valid20020630412h;
proxy_cache_revalidateon;
add_headerX-Cache$upstream_cache_status;
add_headerVia"CDN";
#limit_rate_after4096k;
#limit_rate2048k;
#limit_reqzone=req_addrburst=300nodelay;
#limit_req_status503;
#proxy_limit_rate256000;#64000=1Mbperconnections
proxy_cache_key$scheme$proxy_host$uri;
proxy_cache_lockon;
proxy_cache_lock_timeout10s;
proxy_set_headerHost$host;
proxy_set_headerX-Real-IP$remote_addr;
proxy_set_headerX-Forwarded-For$proxy_add_x_forwarded_for;
proxy_passhttp://backend;
proxy_http_version1.1;
proxy_set_headerConnection"";
}
location~/{
proxy_set_headerHost$host;
proxy_set_headerX-Real-IP$remote_addr;
proxy_set_headerX-Forwarded-For$proxy_add_x_forwarded_for;
proxy_passhttp://backend;
proxy_http_version1.1;
proxy_set_headerConnection"";
}
}