rewrite in custom 404 location

Артём Томюк atomyuk at gmail.com
Tue Jun 27 10:40:08 UTC 2017


is it possible to create "if" rule with rewrite action inside custom 404
location?
the task is fallback to jpg if upstream returns 404 for .webp request.
i've double-checked regexp's - they seems to be write....



location ~* \.(jpg|mp4|svg|jpeg|gif|png|css|bmp|js|swf|webp|jp2|ico)$ {

etag on;

        proxy_cache site;

        proxy_cache_valid  404 302 1m;

        expires max;

        proxy_cache_valid 2h;

        proxy_pass http://cdn;

        proxy_intercept_errors on;

        proxy_connect_timeout 5s;

        proxy_next_upstream error timeout http_404 http_403 http_500
http_502 http_503 http_504;

        error_page 404 /webp.html;

}


location = /webp.html {

        if ($request_filename ~* ^.+.webp$) {

                rewrite ^/(.*)\.webp$ /$1.jpg redirect;

        }

        root /var/www/;

}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx/attachments/20170627/bc2e79eb/attachment.html>


More information about the nginx mailing list