lundi 27 février 2017

Nginx Check Upstream Server Status With If statement

So im trying to check my http_response code from my upstream server, and pass a default response code when the upstream is down; and when the upstream is up proxy all requests to it.

my nginx (NOT WORKING) config looks like this

server {
    listen 80;

    server_name auth.example.com;

    set $upstream 123.456.789.123:8080;


 location @active{
    proxy_pass_header Authorization;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_http_version 1.1;
    proxy_set_header Connection "";
    proxy_buffering off;
    client_max_body_size 10M;
    proxy_read_timeout 36000s;
    proxy_redirect off;
    proxy_pass http://$upstream;
 }

location @outage {
   return 200 "yass!";

 }

location / {
    error_page 500 = @outage;
    set $200 @active;

    if ($http_status != 404){
    return 500;
    }
    if ($http_status = 200) {
      return 200;
    }

}

What i want to achieve is simple, if my upstream server is down return a default 200 response.

if my upstream server is available, proxy all requests to it.

how can i achieve this (a code example would be cool :-)) with nginx.

Aucun commentaire:

Enregistrer un commentaire