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 173 forks source link

多路径域名识别错误 #336

Closed ihufu closed 2 months ago

ihufu commented 3 months ago

Describe the bug 多路径域名识别错误

To Reproduce "/hi": "https://hi.baidu.com", "/hi1": "http://hi1.baiducom"

设置成这样访问hi1 会出现域名识别错误

Screenshots and logs time="2024-06-05 05:57:36" level=info msg="Remote Addr is https://hi.baidu.com1/xxx/6fcede879b3a36b2afc2bd9e3c97987f.jpg, pinging for info..." func="[96:webp_server_go/handler.fetchRemoteImg]"

Environment (please complete the following information):

如日志显示,他识别的域名是hi这个映射的后面还加上了个1

ihufu commented 3 months ago

我用的是.cc的域名,远程获取又变成这样了,Remote Addr is https://hi.xxx.ccm/storage 这是要补齐三位的后缀吗?

n0vad3v commented 3 months ago

请提供完整 config.json 文件和本地所使用的 WebP Server Go 程序版本以及运行方式.

ihufu commented 3 months ago

{ "HOST": "0.0.0.0", "PORT": "3333", "QUALITY": "80", "IMG_PATH": "", "EXHAUST_PATH": "./exhaust", "IMG_MAP": { "/fmg1": "https://fmg1.xxx.net", "/hi1": "http://hi1.xx.cc" }, "ALLOWED_TYPES": ["jpg","png","jpeg","gif","bmp","svg","heic","nef"], "CONVERT_TYPES": ["webp"], "STRIP_METADATA": true, "ENABLE_EXTRA_PARAMS": false, "READ_BUFFER_SIZE": 4096, "CONCURRENCY": 262144, "DISABLE_KEEPALIVE": false, "CACHE_TTL": 259200 }

我的运行方式是docker 0.11.3 版本

n0vad3v commented 3 months ago

根据你所提供的 config.json

{
  "HOST": "0.0.0.0",
  "PORT": "3333",
  "QUALITY": "80",
  "IMG_PATH": "",
  "EXHAUST_PATH": "./exhaust",
  "IMG_MAP": {"/fmg1": "https://fmg1.xxx.net", "/hi1": "http://hi1.xx.cc"},
  "ALLOWED_TYPES": ["jpg", "png", "jpeg", "gif", "bmp", "svg", "heic", "nef"],
  "CONVERT_TYPES": ["webp"],
  "STRIP_METADATA": true,
  "ENABLE_EXTRA_PARAMS": false,
  "READ_BUFFER_SIZE": 4096,
  "CONCURRENCY": 262144,
  "DISABLE_KEEPALIVE": false,
  "CACHE_TTL": 259200
}

我尝试在本地复现,使用如下 docker-compose.yml 文件:

version: '3'

services:
  webp:
    image: webpsh/webp-server-go:0.11.3
    restart: always
    volumes:
      - ./pics:/opt/pics
      - ./exhaust:/opt/exhaust
      - ./metadata:/opt/metadata
      - ./config.json:/etc/config.json
    ports:
      -  127.0.0.1:3333:3333
    command: '/usr/bin/webp-server --config /etc/config.json'

未能复现你的问题,在访问 http://localhost:3333/hi1/path/to/image.jpg 时,容器中 Log 如下:

...
time="2024-06-06 02:19:53" level=info msg="Remote Addr is http://hi1.xx.cc/path/to/image.jpg, pinging for info..." func="[96:webp_server_go/handler.fetchRemoteImg]"
time="2024-06-06 02:19:54" level=info msg="Remote didn't return etag in header when getRemoteImageInfo, please check." func="[138:webp_server_go/handler.pingURL]"
...
ihufu commented 3 months ago

time="2024-06-06 03:35:57" level=info msg="Remote Addr is https://hi.new.cc1/storage/cover/f1bf2866c42e2.jpg, pinging for info..." func="[96:webp_server_go/handler.fetchRemoteImg]" time="2024-06-06 03:35:57" level=error msg="Connection to remote error when pingUrl!" func="[128:webp_server_go/handler.pingURL]"

"IMG_MAP": { "/fmg1": "https://fmg1.cache.com", "/fmg": "https://fmg.ihkmh.com", "/hi": "https://hi.new.cc", "/hi1": "https://hi1.new.cc" },

你在试试这个配置,其他都和上面一样

n0vad3v commented 3 months ago

能复现这个问题了,我们发现问题在于我们匹配域名是根据从上到下的原则匹配的,所以当访问 /hi1/path/to/image.jpg 的时候会在匹配到 "/hi": "https://hi.new.cc/", 时停止,并认为 1/path/to/image.jpg 是实际的图片 URI。

这个行为其实也不是很合理,我们会在后续开发中修复。

目前我们建议有类似 hi1hi 这类同前缀配置时优先写更长的那条(即 /hi1 写在 /hi 的上面一列,类似你给出的例子中的 /fmg1/fmg 上一列一样,这样可以解决当前问题。