<p>I have a question related to Kubernetes Ingress-nginx, I want to use <a href="http://nginx.org/en/docs/http/ngx_http_map_module.html" rel="nofollow noreferrer">ngx_http_map_module</a> to define a new attribute for <a href="https://kubernetes.github.io/ingress-nginx/user-guide/nginx-configuration/log-format/" rel="nofollow noreferrer">log-format-upstream</a>. The respective part in <a href="https://docs.nginx.com/nginx-ingress-controller/installation/installation-with-helm/" rel="nofollow noreferrer">helm chart</a> where I have defined my map looks like this:</p>
<pre><code>containerPort:
   http: 80
   https: 443
 
 config:
   log-format-upstream: $time_iso8601, $proxy_protocol_addr, $proxy_add_x_forwarded_for, $req_id, $remote_user, $bytes_sent, $request_time, $status, $host, $server_protocol, $uri $uri_category

   http-snippet: |
       map $uri $uri_category {
        ~(*/)([0-9]{3,}+)(/*)$ $2;
        }

 configAnnotations: {}
</code></pre>
<p>However, it gives me following error:</p>
<pre><code>nginx: [emerg] unexpected &quot;{&quot; in /tmp/nginx-cfg1517276787:255
</code></pre>
<p>The line 255 in the config looks like this:</p>
<pre><code> proxy_ssl_session_reuse on;
 map $uri $uri_category { #Line: 255
 ~(*/)([0-9]{3,}+)(/*)$ $2;
 }
 
 upstream upstream_balancer {
</code></pre>
<p>I doubt that i havent defined <code>http-snippet</code> and map at the right location in the chart, but i am not sure where exactly it should be either?</p>

<p><a href="https://stackoverflow.com/a/49440631">Related answer</a>: Surround the regex in double-quotes; Nginx uses <code>{</code> and <code>}</code> for defining blocks.</p>
<p>For example:</p>
<pre><code>  map $uri $uri_category {
    &quot;~[0-9]{3,}&quot; 'FOO';
  }

  server {
    location / {
      try_files $uri$uri_category =404;
    }
  }
</code></pre>
<p>That config appends <code>'FOO'</code> to three+ consecutive digits.</p>
<pre><code>/123  -&gt; /123FOO
/4444 -&gt; /4444FOO
</code></pre>
<hr />
<p>In your case, I think the regex should be something like:</p>
<p><code>&quot;~(.*/)([0-9]{3,})(/.*)$&quot; $2;</code></p>
