0

Hi Earlier I was matching location prefix uri matching to get the redirection to website www.example.com/abc/ from www.example.com/bbb/abc(requested uri).

server {
   location /bbb/ {
      proxy_pass http://www.example.com/;
   }

}

Earlier I was requesting on www.example.com/bbb/abc and getting redirected to www.example.com/abc as I required

However now the problem is I've resolver and I'm also using variable. This is done to ensure that nginx starts even if one of the upstream services are down and it won't show the error of

[nginx] host upstream not found

server {
   location /bbb/ {
      resolver 127.0.0.11 valid=some secs;
      set $example www.example.com 
      proxy_pass http://$example/;
   }

}

Now that I'm using variable, I think url location prefix match is not working as I am sending request on www.example.com/bbb/abc , and it shows the nginx 404 not found.

Can anyone guide me how redirect properly with variable and resolver included.

axel
  • 21
  • 7
  • See [this answer](https://stackoverflow.com/a/69899192/4862445) – Richard Smith Nov 15 '21 at 13:33
  • Thanks @RichardSmith. This exactly what I was looking for. However some of the url are getting redirected properly, and few still say not found 404 error. is there any specific reason that some urls work fine whereas other not ? – axel Nov 15 '21 at 14:41
  • Check the access log for the URIs which are causing the 404 error. Do they contain the `/bbb/` prefix? – Richard Smith Nov 15 '21 at 17:13
  • Hi Richard, My issue got fixed, it seems there was some mistake on request uri. Thanks a lot for your help. – axel Nov 17 '21 at 08:05

0 Answers0