首先把 images.weserv.nl 4.x 分支的代码 clone 到本地,然后打开 app/config.lua 源码文件,更改如下:
return {
-- Template options
template = {
name = "API 4 - GitHub, DEMO",
url = "images.weserv.nl",
args = "",
example_image = "ory.weserv.nl/lichtenstein.jpg",
example_transparent_image = "ory.weserv.nl/transparency_demo.png",
example_smartcrop_image = "ory.weserv.nl/zebra.jpg"
},
-- Client options
client = {
-- User agent for this client
user_agent = "Mozilla/5.0 (compatible; ImageFetcher/8.0; +http://images.weserv.nl/)",
-- Sets the connect timeout thresold, send timeout threshold, and read timeout threshold,
-- respetively, in milliseconds.
timeouts = {
connect = 5000,
send = 5000,
read = 15000,
},
-- Number describing the max image size to receive (in bytes). Use 0 for no limits.
max_image_size = 104857600, -- 100 MB
-- Number describing the maximum number of allowed redirects.
max_redirects = 10,
-- Allowed mime types. Use empty table to allow all mime types
allowed_mime_types = {
["image/jpeg"] = "jpg",
["image/png"] = "png",
["image/gif"] = "gif",
["image/bmp"] = "bmp",
["image/tiff"] = "tiff",
["image/webp"] = "webp",
["image/x-icon"] = "ico",
["image/vnd.microsoft.icon"] = "ico",
}
},
-- Throttler options
throttler = {
-- Redis driver
redis = {
scheme = "tcp",
host = "127.0.0.1",
port = 6379,
timeout = 1000, -- 1 sec
-- The max idle timeout (in ms) when the connection is in the pool
max_idle_timeout = 10000,
-- The maximal size of the pool for every nginx worker process
pool_size = 100
},
allowed_requests = 700, -- 700 allowed requests
minutes = 3, -- In 3 minutes
prefix = "c", -- Cache key prefix
whitelist = {
["192.168.1.77"] = true, -- Local IP
["127.0.0.1"] = true, -- Local IP
["192.168.1.168"] = true,
},
policy = {
ban_time = 60, -- If exceed, ban for 60 minutes
cloudflare = {
enabled = false, -- Is CloudFlare enabled?
email = "",
auth_key = "",
zone_id = "",
mode = "block" -- The action to apply if the IP get's banned
}
}
}
}
我们根据自己的运行环境来更改其中的配置项:
- client:配置 imagesweserv 作为客户端向后向的 MinIO 发起获取对象文件的参数;
- throttler:配置限流控制的策略等相关参数;
更改之后,可以开始构建 imagesweserv 镜像,之后再启动相应的容器:
$ docker build . -t imagesweserv\
$ docker run --shm-size=1gb -p 18080:80 -d --name=imagesweserv imagesweserv