Welcome! Log In Create A New Profile

Advanced

Re: map directive using $default as origin

August 10, 2016 01:02AM
Hello steve!

On 08/10/2016 10:47 AM, steve wrote:
> Hi!
>
> On 08/10/2016 03:07 PM, Dewangga Bachrul Alam wrote:
>> Hello!
>>
>> I am using module small_light
>> (https://github.com/cubicdaiya/ngx_small_light), since the module can't
>> detect which browser can process webp transformation, I creating a
>> simple directive on nginx to detect chrome and opera only and fallback
>> the rest to jpeg/jpg.
>>
>> But, if the origin is not jpg (eg: png or gif), the directive transform
>> it into jpg.
>>
>> The snippet looks like :
>>
>> map $http_user_agent $img_mode {
>> $default jpg;
>> ~*chrome webp;
>> ~*opera webp;
>> }
>>
>> ... snip ...
>> location ~ \.(jpe?g|png|gif|webp)$ {
>> root /usr/share/nginx/html;
>> small_light on;
>> small_light_getparam_mode on;
>> rewrite (?<capt>.*) $capt?$args&of=$img_mode break;
>> }
>> ... snip ...
>>
>> Is it possible to give the $default value came from the origin file(s)?
>> So the nginx didn't process png/gif into jpg if using firefox. And will
>> process anything into webp if using Opera/Google Chrome.
>>
>> Many helps are appreciated.
>> Thank you :)
>>
> try using default instead of $default
>

Was changed to `$default default`, and it's works.
Thanks in a bunch.

$ curl -I http://localhost/kartun.png
HTTP/1.1 200 OK
Server: Unyil
Date: Wed, 10 Aug 2016 04:37:35 GMT
Content-Type: image/png
Content-Length: 494553
Last-Modified: Tue, 09 Aug 2016 11:43:38 GMT
Connection: keep-alive
Vary: Accept-Encoding
ETag: "57a9c1ea-76ffe"

_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Subject Author Posted

map directive using $default as origin

dewanggaba August 09, 2016 11:10PM

Re: map directive using $default as origin

GreenGecko August 09, 2016 11:50PM

Re: map directive using $default as origin

dewanggaba August 10, 2016 01:02AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 108
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready