</code></pre></div><p>The preceding ingress definition would translate to the following location block within the NGINX configuration for the <code>test.com</code> server:</p><divclass=highlight><pre><span></span><code>location ~* "^/foo/.*" {
</code></pre></div><h2id=path-priority>Path Priority<aclass=headerlinkhref=#path-prioritytitle="Permanent link"> ¶</a></h2><p>In NGINX, regular expressions follow a <strong>first match</strong> policy. In order to enable more accurate path matching, ingress-nginx first orders the paths by descending length before writing them to the NGINX template as location blocks.</p><p><strong>Please read the <ahref=#warning>warning</a> before using regular expressions in your ingress definitions.</strong></p><h3id=example>Example<aclass=headerlinkhref=#exampletitle="Permanent link"> ¶</a></h3><p>Let the following two ingress definitions be created:</p><divclass=highlight><pre><span></span><code><spanclass=nt>apiVersion</span><spanclass=p>:</span><spanclass="l l-Scalar l-Scalar-Plain">networking.k8s.io/v1beta1</span>
</code></pre></div><p>The ingress controller would define the following location blocks, in order of descending length, within the NGINX template for the <code>test.com</code> server:</p><divclass=highlight><pre><span></span><code>location ~* ^/foo/bar/.+ {
</code></pre></div><p>The following request URI's would match the corresponding location blocks:</p><ul><li><code>test.com/foo/bar/1</code> matches <code>~* ^/foo/bar/.+</code> and will go to service 3.</li><li><code>test.com/foo/bar/</code> matches <code>~* ^/foo/bar/</code> and will go to service 2.</li><li><code>test.com/foo/bar</code> matches <code>~* ^/foo/bar</code> and will go to service 1.</li></ul><p><strong>IMPORTANT NOTES</strong>:</p><ul><li>If the <code>use-regex</code> OR <code>rewrite-target</code> annotation is used on any Ingress for a given host, then the case insensitive regular expression <ahref=https://nginx.org/en/docs/http/ngx_http_core_module.html#location>location modifier</a> will be enforced on ALL paths for a given host regardless of what Ingress they are defined on.</li></ul><h2id=warning>Warning<aclass=headerlinkhref=#warningtitle="Permanent link"> ¶</a></h2><p>The following example describes a case that may inflict unwanted path matching behavior.</p><p>This case is expected and a result of NGINX's a first match policy for paths that use the regular expression <ahref=https://nginx.org/en/docs/http/ngx_http_core_module.html#location>location modifier</a>. For more information about how a path is chosen, please read the following article: <ahref=https://www.digitalocean.com/community/tutorials/understanding-nginx-server-and-location-block-selection-algorithms>"Understanding Nginx Server and Location Block Selection Algorithms"</a>.</p><h3id=example_1>Example<aclass=headerlinkhref=#example_1title="Permanent link"> ¶</a></h3><p>Let the following ingress be defined:</p><divclass=highlight><pre><span></span><code><spanclass=nt>apiVersion</span><spanclass=p>:</span><spanclass="l l-Scalar l-Scalar-Plain">networking.k8s.io/v1beta1</span>
</code></pre></div><p>The ingress controller would define the following location blocks (in this order) within the NGINX template for the <code>test.com</code> server:</p><divclass=highlight><pre><span></span><code>location ~* "^/foo/bar/[A-Z0-9]{3}" {
</code></pre></div><p>A request to <code>test.com/foo/bar/bar</code> would match the <code>^/foo/bar/[A-Z0-9]{3}</code> location block instead of the longest EXACT matching path.</p></article></div></div></main><footerclass=md-footer><divclass=md-footer-nav><navclass="md-footer-nav__inner md-grid"aria-label=Footer><ahref=../fcgi-services/class="md-footer-nav__link md-footer-nav__link--prev"rel=prev><divclass="md-footer-nav__button md-icon"><svgxmlns=http://www.w3.org/2000/svgviewbox="0 0 24 24"><pathd="M20 11v2H8l5.5 5.5-1.42 1.42L4.16 12l7.92-7.92L13.5 5.5 8 11h12z"/></svg></div><divclass=md-footer-nav__title><divclass=md-ellipsis><spanclass=md-footer-nav__direction> Previous </span> Exposing FCGI services </div></div></a><ahref=../external-articles/class="md-footer-nav__link md-footer-nav__link--next"rel=next><divclass=md-footer-nav__title><divclass=md-ellipsis><spanclass=md-footer-nav__direction> Next </span> External Articles </div></div><divclass="md-footer-nav__button md-icon"><svgxmlns=http://www.w3.org/2000/svgviewbox="0 0 24 24"><pathd="M4 11v2h12l-5.5 5.5 1.42 1.42L19.84 12l-7.92-7.92L10.5 5.5 16 11H4z"/></svg></div></a></nav></div><divclass="md-footer-meta md-typeset"><divclass="md-footer-meta__inner md-grid"><divclass=md-footer-copyright> Made with <ahref=https://squidfunk.github.io/mkdocs-material/target=_blankrel=noopener> Material for MkDocs </a></div></div></div></footer></div><scriptsrc=../../assets/javascripts/vendor.93c04032.min.js></script><scriptsrc=../../assets/javascripts/bundle.83e5331e.min.js></script><scriptid=__langtype=application/json>{"clipboard.copy":"Copy to clipboard","clipboard.copied":"Copied to clipboard","search.config.lang":"en","search.config.pipeline":"trimmer, stopWordFilter","search.config.separator":"[\\s\\-]+","search.placeholder":"Search","search.result.placeholder":"Type to start searching","search.result.none":"No matching documents","search.result.one":"1 matching document","search.result.other":"# matching documents","search.result.more.one":"1 more on this page","search.result.more.other":"# more on this page","search.result.term.missing":"Missing"}</script><script>