Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.7k views
in Technique[技术] by (71.8m points)

如何让动态图片地址,在浏览器中转为静态地址,并在浏览器缓存?

比如真实图片地址 http://180.0.0.1?imgid=12345
在浏览器输入 http://domain.com/12345.jpg 会反向代理到真实的地址同时会在浏览器进行图片缓存

nginx 如何配置,能写出详细配置最好了


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

可以试下.大概就是这样.

locaton ~ /.*.jpg {
    rewrite /(.*).jpg /?imgid=$1 break;
    
    expires 30d;
    proxy_set_header Host 180.0.0.1; # 这个地方要把 host 设置为图片保存的原始域名
    proxy_set_header X-Real-IP $remote_addr; # 透传 IP,可要可不要
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; # 透传 IP 可要可不要
    proxy_pass http://180.0.0.1; # 这个地方如果是ip 还好,如果是域名,还涉及到一个反向代理解析 IP 的问题,需要 nginx 配置中加上一个 dns reslover.
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...