0

I have a server and 2 locations. The proxy_pass is the same for both but I need to pass a different header

server {

   location ~ /deployments/*xx*/ {
      proxy_pass $uri;
      proxy_set_header custom-header val1
   }

   location ~ /deployments/*yy*/ {
      proxy_pass $uri;
      proxy_set_header custom-header val2
   }

}

Is this the right way to use regex to accommodate the wildcard uri? What would be the best way to implement this?

4
  • why not use two different request path? it is not very clear what you are doing. moreover what have you been attempting to solve this problem and research?
    – djdomi
    Commented Jun 4 at 4:53
  • The reason I can't use different request paths is because I am not sure how many paths there might be. But all the paths containing 'xx' need header to val1 and paths containing 'yy' need header to val2 Commented Jun 4 at 17:15
  • I have tried location ~ /deployments/*xx*/ { ... } and location ~ /deployments/.*xx.*/ { ... }. Neither seem to work Commented Jun 4 at 17:16
  • you need only /deploy1 and /deploy2 imho
    – djdomi
    Commented Jun 4 at 17:28

1 Answer 1

0

I figured it out, this is the right format

server {

   location ~ ^(/deployments/).*(xx).* {
      proxy_pass $uri;
      proxy_set_header custom-header val1
   }

   location ~ ^(/deployments/).*(yy).* {
      proxy_pass $uri;
      proxy_set_header custom-header val2
   }

}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .