Nginx map value not matched when used as input of another map

Linna.Ding linnading1989 at
Thu Jul 14 17:49:17 UTC 2016

Hi there,

I am having an issue with Nginx map that seems to not match values when the
output variable is the input of another map.

*Case 1: cachestatus_user_agent map is defined separately, not used as
input of wordpress_key map*
*Case 2: cachestatus_user_agent is used as input of wordpress_key map*

Here's my logformat I use to see the results of our maps:
log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                               '$status $body_bytes_sent "$host"
"$http_referer" '
                               '"$http_user_agent" "$http_x_forwarded_for" '
                               '"$upstream_cache_status" "$request_length" '
                               '"$request_time" "$upstream_response_time" '
                               '"$pipe" "$bytes_sent" "$http_pragma" '
                               '"$http_cache_control" "{external_ip}"
"{instance_name}" '
                               '"$scheme"  "$upstream_status"

And then I configure some maps like so:
   http {

       limit_req_zone $wordpress_key zone=wordpress_host:1m rate=1r/m;

* # Here's my initial map*

       map $upstream_cache_status $cachestatus_user_agent {

          HIT $http_user_agent;

          EXPIRED $http_user_agent;

          - $http_user_agent;

          default "";


      *# Successful case, because it starts with a non-mapped var*

map $http_user_agent $wordpress_key {

      *# Failure case, because it starts with a mapped var*

map $cachestatus_user_agent $wordpress_key {

         ~(WordPress) $host;

         default "";


We can see the results below; in the successful case, we see both
cachestatus_map and wordpress_key_map have the expected values:

*Access.log:* - - [13/Jul/2016:16:21:49 -0400] "HEAD / HTTP/1.1" 200 0 "" "-" "WordPress/2.1.1" "-" "HIT" "87" "0.000" "-" "."
"293" "-" "-" "{external_ip}" "{instance_name}" "http"  "-"
"cachestatus_map:WordPress/2.1.1" ""

In the failure case, neither value matches. This is especially weird,
because the first map didn't even change between the two cases.

*Access.log:* - - [13/Jul/2016:16:27:32 -0400] "HEAD / HTTP/1.1" 200 0 "" "-" "WordPress/2.1.1" "-" "HIT" "87" "0.000" "-" "."
"293" "-" "-" "{external_ip}" "{instance_name}" "http"  "-" "cachestatus_map:"

What's weird is that I have another limit_req_zone defined with the same
pattern: two maps linked together, and it works. The limit_req_zone and
maps are defined as below. Both $post_remote_addr and
were printed out when I log them.
     limit_req_zone $post_limited_binary_remote_addr zone=post_ip:1m
     map $request_method $post_remote_addr {
         POST $remote_addr;
         default "";
     map $post_remote_addr $post_limited_binary_remote_addr {
        "" "";
        default $binary_remote_addr;

It seems only $upstream_cache_status has this issue, and I searched around
a bit and couldn't find any public issues related to this. Does anyone have
any thoughts on this?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the nginx-devel mailing list