1

Please help me with nginx.conf that is regex and multi location.

When I create the nginx.conf with next location, proxy_pass works correctly:

location = /test-a-1-1 {
       proxy_pass http://test-a-1-1;
       proxy_set_header Host $host;
       proxy_set_header X-Real-IP $real_remote_addr;
       proxy_redirect off;
   }

  location = /test-b-1-2 {
      proxy_pass http://test-b-1-2;
      proxy_set_header Host $host;
      proxy_set_header X-Real-IP $real_remote_addr;
      proxy_redirect off;
  }

But I have many locations and I want use multi location, but in this configuration i get the error -

test-b-1-2 could not be resolved (3: Host not found)

resolver 172.16.10.3
location ~ ^/(test-a-[0-9]-[0-9]|test-b-[0-9]-[0-9]) {
                set $test $1;
                proxy_pass http://$test;
                proxy_set_header Host $host;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_redirect off;
                }

Please help me with regex and multi locations. Thank you.

  • 1
    If you are using a variable in the proxy_pass statement, you may need to define a resolver. See this document. – Richard Smith Jul 31 at 17:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.