2
location / {
    proxy_pass       http://image_server:8000;
}

In normal case, the proxy server will return image/png. But in other cases (for example out of bandwidth), it will throw application/json (with 200 HTTP) instead of images. So how to only accept images from the proxy, I want to show a 500 error page instead of it returning application/json from the proxy

user2477
  • 896
  • 2
  • 10
  • 23

1 Answers1

2

An openresty/lua-ngx-module solution:

location / {
    proxy_pass       http://image_server:8000;
    header_filter_by_lua_block {
        if string.find( ngx.header.content_type, "json" ) then
            ngx.exit(500)
        end
    }
}

or

location / {
    proxy_pass       http://image_server:8000;
    header_filter_by_lua_block {
        if string.find( ngx.header.content_type, "image/" ) == nil then
            ngx.exit(500)
        end
    }
}
Ivan Shatsky
  • 13,267
  • 2
  • 21
  • 37