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

MultiPath(IMG_MAP) not working #349

Closed junyangfan closed 1 month ago

junyangfan commented 1 month ago

I am very happy to have used such a great project, but I encountered a problem while using it and hope to receive an answer.

My folder is as follows:

root@debian:~/webpgo# ls
config.json  docker-compose.yml   pics

The pics folder contains a test-1.png image

docker-compose.yml

version: '3'

services:
  webpgo:
    container_name: webpgo
    image: webpsh/webp-server-go
    restart: always
    volumes:
      - ./pics:/opt/pics
      - ./exhaust:/opt/exhaust
      - ./metadata:/opt/metadata
      - ./config.json:/etc/config.json
    ports:
      -  "23333:3333"

config.json

{
  "HOST": "0.0.0.0",
  "PORT": "3333",
  "QUALITY": "90",
  "IMG_PATH": "",
  "EXHAUST_PATH": "/opt/exhaust",
  "IMG_MAP": {
    "/images": "/opt/pics"
  },
  "ALLOWED_TYPES": ["jpg", "png", "jpeg", "bmp", "gif", "svg", "heic", "nef", "webp"],
  "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": 0,
}

When I start the service with the docker compose up - d command, And after configuring the basic nginx reverse proxy

server {
  server_name example.com;
  listen 443 ssl;
  http2 on;
  ssl_certificate xxx.cer;
  ssl_certificate_key xxx.key;
  ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
  listen 80;
  if ($scheme = http) {
    return 301 https://$host:443$request_uri;
  }
  location / {
    proxy_pass http://127.0.0.1:23333;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Host $http_host;
    proxy_set_header X-Forwarded-Port $server_port;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_redirect http:// https://;
  }
}

https://example.com/images/test-1.png not working,tip: Image not found!

https://example.com/test-1.png is working,

Why did this situation occur, expected https://example.com/images/test-1.png is working,https://example.com/test-1.png not working.

I am using the latest webpsh/webp-server-go image

And I want to use it with my self built Minio S3 storage service. How should I proceed?

I am very confused about this and hope to receive an answer,thanks

n0vad3v commented 1 month ago

Thanks for feedback, the problem here is that the config.json is not a valid JSON file(which caused WebP Server using the default configuration), there is an extra , at the last line of it, so instead of

  "MAX_CACHE_SIZE": 0,
}

it should be

  "MAX_CACHE_SIZE": 0
}

BTW I see there's a related error on our documentation site, I've fixed at commit: https://github.com/webp-sh/docs.webp.sh/commit/e8162c1dea7c510c41b0cb2d6edb99fa8d753167 We'll add a feature to panic WebP Server on invalid configuration so the server will not silently use default value in this condition.

And I want to use it with my self built Minio S3 storage service. How should I proceed?

You can refer to https://docs.webp.sh/usage/multipath/ to proxy to your Minio endpoint, for example:

"IMG_MAP": {
  "/images": "/opt/pics",
  "/s3images": "http://your-minio.host"
},
junyangfan commented 1 month ago

Thanks for feedback, the problem here is that the config.json is not a valid JSON file(which caused WebP Server using the default configuration), there is an extra , at the last line of it, so instead of感谢您的反馈,这里的问题是config.json不是一个有效的 JSON 文件(这导致 WebP Server 使用默认配置),在它的最后一行有一个额外的, ,所以而不是

  "MAX_CACHE_SIZE": 0,
}

it should be 它应该是

  "MAX_CACHE_SIZE": 0
}

BTW I see there's a related error on our documentation site, I've fixed at commit: webp-sh/docs.webp.sh@e8162c1顺便说一句,我看到我们的文档网站上有一个相关错误,我已在提交时修复: webp-sh/docs.webp.sh@ e8162c1 We'll add a feature to panic WebP Server on invalid configuration so the server will not silently use default value in this condition.我们将添加一项功能,以便在配置无效时让 WebP 服务器恐慌,这样服务器在这种情况下就不会默默地使用默认值。

And I want to use it with my self built Minio S3 storage service. How should I proceed?我想将它与我自己构建的 Minio S3 存储服务一起使用。我应该如何进行?

You can refer to https://docs.webp.sh/usage/multipath/ to proxy to your Minio endpoint, for example:您可以参考https://docs.webp.sh/usage/multipath/来代理您的 Minio 端点,例如:

"IMG_MAP": {
  "/images": "/opt/pics",
  "/s3images": "http://your-minio.host"
},

Thank you for your reply, which helped me resolve my doubts,It's very nice.