0

Currently I am using Nginx with Kubernetes. In my Nginx conf file I have the following proxy pass:

location ~ /myPath/([\w-]+)/resources {
    rewrite ^/myPath/([\w-]+)/resources/(.*)$ /myNewPath/$1/resources/$2 break;
    proxy_pass http://$1;
}

Currently Nginx complains that it is unable to resolve the $1 at runtime to perform the proxy_pass (despite us having our SkyDNS resolver specified i.e. resolver 10.250.0.5 valid=5s).

We need this to be done dynamically because at Nginx start up the value of $1 may not be known and must be resolved when requested.

Is Nginx capable of doing this dynamic DNS resolution on the fly?

1 Answers1

1

Yes, Nginx can do dynamic resolution.

However, your regular expression may be flawed. The regex of ([\w-]+) would /not/ match a dot character when used with the PCRE engine. You can test that on https://regex101.com/

According to the PCRE docs:

A "word" character is an underscore or any character that is a letter or digit.

So your regex would work for values like "short-host-name", but not "fully-qualified.example.com".

Mark Stosberg
  • 3,771
  • 23
  • 27