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.85k stars 176 forks source link

Bypass some file extensions #267

Closed YrracOwl closed 7 months ago

YrracOwl commented 1 year ago

Is your feature request related to a problem? Please describe. My font file and imags are stored under a samge directory named "data", but I just only want webp-server to handle images but bypass the font file ( .woff2 ).

Describe the solution you'd like I ran this webp-server-go by docker, so I would like to use environment to config the bypass file extension.

Describe alternatives you've considered config.json is also OK.

Additional context I didn't find any information of proxying files, if this is a function that is already be implemented, can you give me the documention link or something else?

n0vad3v commented 1 year ago

webp-server-go by docker

Are you using WebP Server Go to directly serve files?(e,g listening on port 80)

If you have a reverse proxy(like Nginx) in front of WebP Server Go, you can write configuration that only forward image requests to WebP Server Go, as below:

location ~* \.(?:jpg|jpeg|gif|png)$ {
    proxy_pass http://127.0.0.1:3333;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_hide_header X-Powered-By;
    proxy_set_header HOST $http_host;
    add_header Cache-Control 'no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0';
}

Related docs page: https://docs.webp.sh/usage/usage-with-binary/

YrracOwl commented 1 year ago

webp-server-go by docker

Are you using WebP Server Go to directly serve files?(e,g listening on port 80)

If you have a reverse proxy(like Nginx) in front of WebP Server Go, you can write configuration that only forward image requests to WebP Server Go, as below:

location ~* \.(?:jpg|jpeg|gif|png)$ {
    proxy_pass http://127.0.0.1:3333;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_hide_header X-Powered-By;
    proxy_set_header HOST $http_host;
    add_header Cache-Control 'no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0';
}

Related docs page: https://docs.webp.sh/usage/usage-with-binary/

Actually I'm using cloudflare zero trust to bind webp-server with my domains, because I deployed webp-server-go on my NAS, and I can't get a public IP.

But your reply inspire me, thx a lot. I'll do some research.

BennyThink commented 1 year ago

bypass you mean throw an error File extension not allowed! gif-animated.gif or return what it is? If you want the second one, using nginx to pass only images is the best option for now.