如何用 nginx 重写无效的图片 url
how to rewrite invalid images urls with nginx
我有这样的图片路径
www.domain.com/i/1.png
但是这张图片不存在所以我想重写 url 来显示这张图片
www.domain.com/i/0.jpg
您可以使用 try_files
进行此类检查。 try_files
仅在 nginx 用作 local 文件的网络服务器时才有效。
https://nginx.org/en/docs/http/ngx_http_core_module.html#try_files
location /i/ {
try_files $uri /i/0.jpg;
}
location = /i/0.jpg {
expires 30s;
}
我有这样的图片路径
www.domain.com/i/1.png
但是这张图片不存在所以我想重写 url 来显示这张图片
www.domain.com/i/0.jpg
您可以使用 try_files
进行此类检查。 try_files
仅在 nginx 用作 local 文件的网络服务器时才有效。
https://nginx.org/en/docs/http/ngx_http_core_module.html#try_files
location /i/ {
try_files $uri /i/0.jpg;
}
location = /i/0.jpg {
expires 30s;
}