项目路径
/root/.halo
项目缓存路径
/root/.halo/cache
项目开源地址
https://github.com/webp-sh/webp_server_go/releases
项目开源文档
https://docs.webp.sh/usage/prefetch/
新建一个存放二进制文件和 config.json 文件的目录(可自定义):
mkdir /opt/webps
cd /opt/webps
下载二进制文件(最新版本请访问 releases)
wget https://ghproxy.com/https://github.com/webp-sh/webp_server_go/releases/download/0.4.0/webp-server-linux-amd64 -O webp-server
PS:0.2.0版本之后的版本 需要新的依赖包支持
yum install libaom-devel -y
添加可执行权限
chmod +x webp-server
配置文件
vim /opt/webps/config.json
{
"HOST": "127.0.0.1",
"PORT": "3333",
"QUALITY": "80",
"IMG_PATH": "/root/.halo",
"EXHAUST_PATH": "/root/.halo/cache",
"ALLOWED_TYPES": ["jpg","png","jpeg","bmp"],
"ENABLE_AVIF": false
}
服务文件
vim /etc/systemd/system/webp-server.service
[Unit]
Description=WebP Server Go
Documentation=https://github.com/webp-sh/webp_server_go
After=nginx.target
[Service]
Type=simple
StandardError=journal
WorkingDirectory=/opt/webps
ExecStart=/opt/webps/webp-server --config /opt/webps/config.json
Restart=always
RestartSec=3s
[Install]
WantedBy=multi-user.target
服务自启-启动-状态查看
systemctl daemon-reload
systemctl enable webp-server.service
systemctl start webp-server.service
systemctl status webp-server.service
nginx反向代理配置
在server节点添加
location ^~ /upload/ {
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';
}
重载 Nginx 配置:
# 检查配置文件是否有问题
nginx -t
nginx -s reload
评论区