Nginx does not serve avif

Francis Daly francis at daoine.org
Thu Oct 6 21:43:32 UTC 2022


On Thu, Oct 06, 2022 at 02:30:08PM +0200, Martin Wolfert wrote:

Hi there,

> In "/var/www/htdocs/blog.lichttraeumer.de/wp-content/uploads/2022/05" i have
> located .jpg, .webp and .avif files:

Thanks for the details.

Both ideas seem to work for me, when testing with curl:

===
$ cat /etc/nginx/conf.d/test-avif.conf
server {
        listen 127.0.0.5:80;
        root /tmp/t3;

        set $img_suffix "";
        if ($http_accept ~* "webp") {
                set $img_suffix ".webp";
        }
        if ($http_accept ~* "avif") {
                set $img_suffix ".avif";
        }
        location ~ \.(jpg|png)$ {
                try_files $uri$img_suffix $uri $uri/ =404;
        }
}
$ mkdir /tmp/t3
$ echo one.png > /tmp/t3/one.png
$ echo one.png.avif > /tmp/t3/one.png.avif

$ curl http://127.0.0.5/one.png
one.png
$ curl -H Accept:webp http://127.0.0.5/one.png
one.png
$ curl -H Accept:avif http://127.0.0.5/one.png
one.png.avif

===
$ cat /etc/nginx/conf.d/test-avif-map.conf
map $http_accept $webp_suffix {
        "~image/webp" "$uri.webp";
}
map $http_accept $avif_suffix {
        "~image/avif" "$uri.avif";
}

server {
        listen 127.0.0.6:80;
        root /tmp/t4;

        location ~ \.(jpg|jpeg)$ {
                try_files $avif_suffix $webp_suffix $uri =404;
        }
}
$ mkdir /tmp/t4
$ echo one.jpg > /tmp/t4/one.jpg
$ echo one.jpg.webp > /tmp/t4/one.jpg.webp
$ echo one.jpg.avif > /tmp/t4/one.jpg.avif
$ echo two.jpg.webp > /tmp/t4/two.jpg.webp

$ curl http://127.0.0.6/one.jpg
one.jpg
$ curl -H Accept:image/avif http://127.0.0.6/one.jpg
one.jpg.avif
$ curl -H Accept:image/webp http://127.0.0.6/one.jpg
one.jpg.webp
$ curl -H Accept:image/other http://127.0.0.6/one.jpg
one.jpg
$ curl -H Accept:image/avif,image/webp http://127.0.0.6/one.jpg
one.jpg.avif
$ curl -H Accept:image/avif,image/webp http://127.0.0.6/two.jpg
two.jpg.webp
$

===

Do they work for you, when testing with curl?

If not -- why not / what is different between your test config and my test config?

And if so -- what is different between the curl request and the Firefox request?

Thanks,

	f
-- 
Francis Daly        francis at daoine.org



More information about the nginx mailing list