[英]In Nginx, redirect to another site if img is down
我有一個使用一些舊鏈接 png 的網站,例如:
<img src="http://j.cd.top/uploads/jvyue/news/2020/04/10/15864804147273771862.png" style="height:211px; width:330px">
並且 png 不存在,所以我嘗試通過設置 Nginx 將其重寫到本地服務器:
location ~ .*\.(gif|jpg|jpeg|png)$ {
try_files $uri @apache; }
location @apache{
rewrite ^http://j.cd.top/uploads/(.*)$ http://127.0.0.1:8222/$1 permanent;
}
http://127.0.0.1:8222是服務器圖像的本地服務器,但是這個設置不起作用,有什么問題嗎?
http://j.cd.top/uploads不是當前網站,它是舊鏈接。
我也試過代理通行證:
location ~* \.(gif|jpg|jpeg|png)$ {
proxy_pass http://127.0.0.1:8222;
}
通過rewrite
指令測試的 $uri 變量中不包含方案和主機名,試試這個:
rewrite ^/uploads/(.*)$ http://127.0.0.1:8222/$1 permanent;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.