Home > Blockchain >  Syntax error when defining a map under a http-snippet in nginx chart
Syntax error when defining a map under a http-snippet in nginx chart

Time:10-02

I have a question related to Kubernetes Ingress-nginx, I want to use ngx_http_map_module to define a new attribute for log-format-upstream. The respective part in helm chart where I have defined my map looks like this:

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: {}

However, it gives me following error:

nginx: [emerg] unexpected "{" in /tmp/nginx-cfg1517276787:255

The line 255 in the config looks like this:

 proxy_ssl_session_reuse on;
 map $uri $uri_category { #Line: 255
 ~(*/)([0-9]{3,} )(/*)$ $2;
 }
 
 upstream upstream_balancer {

I doubt that i havent defined http-snippet and map at the right location in the chart, but i am not sure where exactly it should be either?

CodePudding user response:

Related answer: Surround the regex in double-quotes; Nginx uses { and } for defining blocks.

For example:

  map $uri $uri_category {
    "~[0-9]{3,}" 'FOO';
  }

  server {
    location / {
      try_files $uri$uri_category =404;
    }
  }

That config appends 'FOO' to three consecutive digits.

/123  -> /123FOO
/4444 -> /4444FOO

In your case, I think the regex should be something like:

"~(.*/)([0-9]{3,})(/.*)$" $2;

  • Related