Score:1

how to make a redirect conditional on nginx conf

cg flag

I should make a conditional rediction in nginx. I would like to do something like that.

$http_code = code from curl commande

if ( $http_code = 200 ){

"redirection to server 1"

}

else {

"redirection to server 2"

}

So can someone help me to find a way to do it, or give me example of nginx conf with condition like this.

Thanks

djdomi avatar
za flag
https://serverfault.com/questions/1003406/how-can-i-do-a-redirect-with-404-as-status-code-in-nginx the same imho can be used for any other
khaled avatar
cg flag
I have already seen this post and it does not answer my request, because i want to make a test and the rediction will be to another server depending to result
djdomi avatar
za flag
location = /foo { error_page 404 = @ext_404; } location @ext_404 { proxy_pass https://bar.example.com; it does not answer it? it DOES
djdomi avatar
za flag
You can join me on https://chat.stackexchange.com/rooms/126791/thechat and we will discuss this sutation with some words
khaled avatar
cg flag
Thank you for your proposal, but i don't have enough of right to acces to the chat
djdomi avatar
za flag
now oyu should :-)
khaled avatar
cg flag
i have this message "You must have 20 reputation on The Stack Exchange Network to talk here" that's why i can't be on the chat
us flag
I don't think basic nginx has feature to implement such conditional processing based on results on requests to other parts. You need to use either nginx JS module or LUA module with an appropriate script to implement this logic.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.