Welcome! Log In Create A New Profile

Advanced

Redirect request based on request type in case of error

Posted by devkuamr 
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".

Posted at Nginx Forum: https://forum.nginx.org/read.php?2,278044,278044#msg-278044

_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Francis Daly
Re: Redirect request based on request type in case of error
January 10, 2018 12:20PM
On Tue, Jan 09, 2018 at 01:04:22AM -0500, devkuamr wrote:

Hi there,

> 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.

> if ($request_method = POST){
> return upstream_status;
> }

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

I don't immediately know about the rest of it, but I suspect there's a
good chance that you want $upstream_status instead of upstream_status.

f
--
Francis Daly francis@daoine.org
_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Sorry, only registered users may post in this forum.

Click here to login