【发布时间】:2021-05-08 10:26:51
【问题描述】:
我正在使用 ShortPixel 创建名为 image.webp 的 WEBP 图像,并保存在与 image.jpg 相同的文件夹中。
- 我在 etc/nginx/conf.d/webp.conf 中添加了这个:
map $http_accept $webp_suffix {
default "";
"~*webp" ".webp";
}
并在nginx配置文件中添加include etc/nginx/conf.d/*.conf。
- 在 etc/nginx/conf.d/site.conf 中添加了这个
location ~* ^(/wp-content/.+)\.(png|jpe?g)$ {
set $base $1;
set $webp_uri $base$webp_suffix;
set $webp_old_uri $base.$2$webp_suffix;
set $root "FULL PATH OF wp-content PARENT";
root $root;
add_header Vary Accept;
if ( !-f $root$webp_uri ) {
add_header X_WebP_SP_Miss $root$webp_uri;
}
try_files $webp_uri $webp_old_uri $uri =404;
}
检查nginx -t,一切正常。但是在 devtool/network 选项卡中,图像类型仍然是 jpg。这是为什么呢?
【问题讨论】:
标签: php wordpress nginx server webp