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.

2
  • 1
    Not really. You can either have nginx pass through the errors from the backend, or serve a static document. Sep 1, 2015 at 21:19
  • Your example is confusing.
    – Alexey Ten
    Sep 2, 2015 at 5:03

1 Answer 1

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .