Welcome! Log In Create A New Profile

Advanced

Redirect request based on request type in case of error

January 09, 2018 01:04AM
Hi,
I want to redirect GET request to another server in case of errors. I am using the below configuration but nginx is having problem while starting with this configuration.

worker_processes 8;
events {
worker_connections 1024;
}
http {
include mime.types;
include map.txt;
default_type application/octet-stream;
sendfile on;

upstream 271889976{
server 172.198.1.19:8080;
}

upstream 271889979{
server 172.198.1.18:8080;
}


upstream backup {
server 172.198.1.20:8080;
}

server {
listen 8080;
server_name localhost;
proxy_intercept_errors on;
error_page 502 @redirect;
proxy_read_timeout 10s;
location / {
proxy_pass http://$newhost$request_uri;
proxy_hide_header store;
}
location @redirect{
if ($request_method = GET){
proxy_pass http://backup$request_uri;
break;
}
if ($request_method = POST){
return upstream_status;
}

}

}

include servers/*;
}

I am getting "invalid return code "upstream_status"" with above configuration file.

For POST request I want the same error returned by server. and in case of GET I want request to be redirected on "backup upstream".
Subject Author Posted

Redirect request based on request type in case of error

devkuamr January 09, 2018 01:04AM

Re: Redirect request based on request type in case of error

Francis Daly January 10, 2018 06:20AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 146
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 500 on July 15, 2024
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready