缘由:
有一套环境部署在aws 新加坡区,资源使用s3对象存储,也用了cloudfront加速,但是but国内访问最近抽筋,也特意看了一下解析的地址IP....加速的地址在usa.....资源加速太慢了就想到了用nginx缓存加速一下!当然了还可以用国内腾讯云cos or 阿里云oss同步到国内?但是生命周期,同步成本估计会很高,就简单用nginx先尝试一下了!
顺便尝试问了一下chatgpt:
简单配置使用
就这样简单配置了一下: cat xxx.xxx.com.conf
proxy_cache_path /data/wwwroot/xxx.xxx.com levels=1:2 keys_zone=s3_cache:10m max_size=1g inactive=60m use_temp_path=off;
server {
listen 80;
listen 443 ssl http2;
ssl_certificate /usr/local/tengine/conf/ssl/xxx.com.crt;
ssl_certificate_key /usr/local/tengine/conf/ssl/xxx.com.key;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
ssl_ciphers TLS13-AES-256-GCM-SHA384:TLS13-CHACHA20-POLY1305-SHA256:TLS13-AES-128-GCM-SHA256:TLS13-AES-128-CCM-8-SHA256:TLS13-AES-128-CCM-SHA256:EECDH+CHACHA20:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5;
ssl_prefer_server_ciphers on;
ssl_session_timeout 10m;
ssl_session_cache builtin:1000 shared:SSL:10m;
ssl_buffer_size 1400;
add_header Strict-Transport-Security max-age=15768000;
ssl_stapling on;
ssl_stapling_verify on;
server_name xxx.xxx.com;
access_log /data/wwwlogs/xxx.xxx.com_nginx.log combined;
index index.html index.htm index.php;
root /data/wwwroot/xxx.xxx.com;
if ($ssl_protocol = "") { return 301 https://$host$request_uri; }
include /usr/local/tengine/conf/rewrite/none.conf;
#error_page 404 /404.html;
#error_page 502 /502.html;
location / {
proxy_http_version 1.1;
proxy_pass http://xxx.s3.ap-southeast-1.amazonaws.com;
proxy_set_header Authorization "";
proxy_hide_header x-amz-id-2;
proxy_hide_header x-amz-request-id;
proxy_hide_header Set-Cookie;
proxy_ignore_headers "Set-Cookie";
proxy_cache s3_cache;
proxy_cache_valid 200 302 1h;
proxy_cache_valid 403 404 500 502 503 504 1m;
add_header X-Cache-Status $upstream_cache_status;
}
}
注意:nginx server 使用oneinstack搭建,用了十多年的一键lnmp搭建工具!只增加了proxy_cache_path 配置,修改了location 配置。 reload 加载配置!
systemctl restart nginx
or
systemctl reload nginx
完美实现,跟小伙伴开玩笑,打钱哈哈哈 有同样需求的可以尝试用nginx代理一下,当然了缓存时间,缓存文件最大大小等参数有必要根据实际优化一下!
标签:cache,ssl,s3,xxx,用法,nginx,proxy,com From: https://blog.51cto.com/saynaihe/6719952