Nginx 反向代理 JsDelivr
nginx 缓存配置
nginx
proxy_temp_file_write_size 128k;
proxy_temp_path /nginx_cache/proxy_temp;
proxy_cache_path /nginx_cache/googlefonts levels=1:2 keys_zone=googlefonts:200m inactive=30d max_size=1g;
proxy_cache_path /nginx_cache/gravatar levels=1:2 keys_zone=gravatar:200m inactive=30d max_size=1g;
proxy_cache_path /nginx_cache/jsdelivr levels=1:2 keys_zone=jsdelivr:200m inactive=30d max_size=1g;
反向代理 JsDelivr
批量修改 jsdelivr.yourdomain.com 为你的域名
nginx
upstream jsdelivr {
server cdn.jsdelivr.net:443;
}
server {
listen 80;
server_name jsdelivr.yourdomain.com;
return 301 https://jsdelivr.yourdomain.com$request_uri;
}
server {
listen 443 ssl http2;
server_name jsdelivr.yourdomain.com;
index index.html index.htm index.php default.html default.htm default.php;
ssl_certificate /ssl/yourdomain.com.cer;
ssl_certificate_key /ssl/yourdomain.com.key;
ssl_trusted_certificate /ssl/yourdomain.com.cer;
ssl_stapling on;
ssl_stapling_verify on;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_prefer_server_ciphers off;
ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384;
ssl_ecdh_curve secp384r1;
ssl_session_timeout 10m;
ssl_session_cache builtin:1000 shared:SSL:10m;
ssl_session_tickets off;
resolver 8.8.8.8 8.8.4.4 valid=60s ipv6=off;
resolver_timeout 5s;
add_header Strict-Transport-Security "max-age=63072000" always;
location / {
proxy_pass https://jsdelivr;
proxy_set_header Host cdn.jsdelivr.net;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_http_version 1.1;
proxy_set_header Connection "";
proxy_ssl_server_name on;
add_header X-Cache $upstream_cache_status;
proxy_ignore_headers Set-Cookie Cache-Control expires;
proxy_cache jsdelivr;
proxy_cache_valid 200 304 365d;
proxy_cache_key $host$uri$is_args$args;
expires max;
}
access_log /var/log/nginx/jsdelivr.yourdomain.com.access.log main;
error_log /var/log/nginx/jsdelivr.yourdomain.com.error.log warn;
}