侧边栏壁纸
博主头像
laoliyun

生活总是这样,不能叫人处处都满意,但我们还要热情地活下去,人活一生值得爱的东西很多,不要因为一个不满意就灰心。

  • 累计撰写 129 篇文章
  • 累计创建 44 个标签
  • 累计收到 0 条评论

目 录CONTENT

文章目录
Web

halo webp-server

laoliyun
2022-06-30 / 0 评论 / 0 点赞 / 293 阅读 / 424 字
温馨提示:
本文最后更新于 2022-07-09,若内容或图片失效,请留言反馈。部分素材来自网络,若不小心影响到您的利益,请联系我们删除。

项目路径

/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

参考阅读

使用 WebP Server Go 优化图片提升网站加载速度 - 少数派 (sspai.com)

优雅的让 Halo 支持 webp 图片输出 | Halo

0

评论区