1

I'm looking for a way to serve up a static message from nginx if an upstreams section returns certain HTTP codes. I understand that I could use static pages and ask NGINX to serve these up, but this is slightly more complicated that I need - all really need is (in pseudocode) to say

if($code_from_proxy_upstream == 500){
   return 500 'Error Occured'
}

I Read this question and this question, but I don't think that they quite do what I need. I think that I need some combination of the two, but not quite sure of the syntax.

phatmanace
  • 191
  • 2
  • 10

1 Answers1

1

I pretty much got this to work.

I added a set of directives like this:

error_page 508 @myerrordirective_508;

and then

location @myerrordirective_508{
   return 508 "Error Occured"
}

The only pain was that nginx doesn't seem to allow me to use a variable to refer to the status (so that I could have just had one block with $status or whatever in it, which meant that each status needed an error_page and a location block.I therefore used a script to generate lines like the above for each error code, and put these into an include file which I linked from the main config

Seemed to do what I wanted.

phatmanace
  • 191
  • 2
  • 10