A
A
Alex2017-03-29 10:49:59
Nginx
Alex, 2017-03-29 10:49:59

How to change nginx image?

There are two pictures on the site.

/images/image.jpg
/images/image.webp

It is necessary that, when requested, it should be /images/image.jpgreturned /images/image.webpon the condition that in request headerAccept:image/webpi.e. browser supports webp format.
As a result, if I open /images/image.jpgit in such a browser, I will see in the response headers Content-Type:image/webp, and Content-Lengthit will correspond to/images/image.webp

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Andrey Burov, 2017-03-29
@BuriK666

something like this:

if ($http_accept ~* "image/webp") { 
      rewrite ^/(.*)\.jpg$ /$1.webp;
}

A
Andrey Shatokhin, 2017-03-29
@Sovigod

Convenient conversion and substitution for the desired format is in the pagespeed module from Google.
https://github.com/pagespeed/ngx_pagespeed

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question