禁止访问指定目录
location ^~ /docker/ {
deny all;
}
指定图片资源访问不到时走后端代理服务拿
location ~* ^/imgs/images/gift/webp/ {
error_page 404 =200 @liveGiftImageWebp;
}
location @liveGiftImageWebp {
rewrite /imgs/images/gift/webp/(\d+)\..*$ /gift/img?id=$1 break;
proxy_pass http://api;
}
这个配置把访问类似 /imgs/images/gift/webp/2334.webp这样的资源,当访问不到时,重定向到api项目,访问路径重写为 /gift/img?id=2334
api项目输出图片。代码类似如下
<?php
$img = file_get_contents($url, true);
//使用图片头输出浏览器
header("Content-Type: image/jpeg;text/html; charset=utf-8");
echo $img;
通过file_get_contents拿到图片内容,header一个图片的头,之后输出图片