NGINX redirect attempts download instead of rendering image

imagesnginxPHP

I've got a PHP page that renders a dynamic image

/scripts/oem-image.php?brand=$1&sku=$2 break;

I'm trying to do a background redirect (keep the original url) from a .jpg link. For instance, if you requested

/media/catalog/product/oem-label/honda/3580-hn7-004.jpg

it would display the image from the following URL but would still show the above URL in the address bar

/scripts/oem-image.php?brand=honda&sku=3580-hn7-004

Here's what I've got in the nginx config. The only problem is that when you try to go to the /media/... link, it attempts to download the file rather than simple displaying it.

location /media/catalog/product/oem-label/ {
  rewrite ^/media/catalog/product/oem-label/(.*)/(.*).jpg$ /scripts/oem-image.php? brand=$1&sku=$2 break;
}

ADDITIONAL INFO

I'm setting

<?php header("Content-type: image/jpeg"); ?>

and have also tried

<?php header("Content-disposition: inline"); ?>

Best Answer

Try to switch break by last in your redirect