webp-sh / webp_server_go

Go version of WebP Server. A tool that will serve your JPG/PNG/BMP/SVGs as WebP/AVIF format with compression, on-the-fly.
https://docs.webp.sh
GNU General Public License v3.0
1.79k stars 172 forks source link

关于非图片资源自动回源的问题 #351

Open woodchen-ink opened 1 month ago

woodchen-ink commented 1 month ago

据我了解, 现在本项目是不支持这个的, 需要自行在nginx里做分流.

但是有一个问题, 我当前使用的是IMG_MAP, 也就是有多个回源策略, 这个就很不方便在nginx里做分流的, 希望可以支持 "非图片" 自动回源并返回资源的功能.

谢谢

n0vad3v commented 1 month ago

我们有过一些类似的 Issue:

我当前使用的是IMG_MAP, 也就是有多个回源策略, 这个就很不方便在nginx里做分流的

请问可以详细描述一下你的使用场景嘛?

woodchen-ink commented 1 month ago

嗯嗯, 这些issue我都看了, 比如我的config.json:

{
  "HOST": "0.0.0.0",
  "PORT": "3333",
  "QUALITY": "80",
  "EXHAUST_PATH": "./exhaust",
  "IMG_MAP": {
    "/minio-sh1": "https://minio.example.net",
    "/oracle": "https://oracle-example.net",
    "/r2": "https://r2-cloudflare.example.net",
    "/qiniu": "https://cdn-qiniu.example.net",
    "/exp": "https://exp.example.net",
    "/czl": "https://example.net",
    "/v": "./v",
    "/webp": "https://mirror.example.net"
  },
  "ALLOWED_TYPES": ["*"],
  "CONVERT_TYPES": ["webp"],
  "STRIP_METADATA": true,
  "ENABLE_EXTRA_PARAMS": true,
  "EXTRA_PARAMS_CROP_INTERESTING": "InterestingAttention",
  "READ_BUFFER_SIZE": 4096,
  "CONCURRENCY": 262144,
  "DISABLE_KEEPALIVE": false,
  "CACHE_TTL": 259200,
  "MAX_CACHE_SIZE": 4096
}

我有多个存储桶, 例如cloudflare r2, oracle, minio, 我通过两个webp-server-go项目 (一个在CN, 一个在SG) 来处理他们里面的内容, 但是因为有一些旧资源, 还有例如q58.org这个论坛, 是可以上传多种资源的(图片外). 当前策略是:

用户上传 - 存储桶 - 通过webp-server-go访问

目前图片外的资源的都无法访问.

而且考虑到这个技术也不是很难实现, 只是在回源时已有的条件判断处加一个额外处理, 就可以满足很多例外情况.

如果本身回源不好做, 也许可以 302跳转 ?