<div dir="ltr"><div><div class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div dir="ltr"><div><div>Hi there,</div></div><div><br></div><div><div><span style="line-height:1.5">I am having an issue with Nginx map that seems to not match values when the output variable is the input of another map.</span><br></div><span class="im"><div><br></div><div><b>Case 1: cachestatus_user_agent map is defined separately, not used as input of wordpress_key map</b></div><div><b>Case 2: cachestatus_user_agent is used as input of wordpress_key map</b></div><div><br></div></span><div>Here's my logformat I use to see the results of our maps:</div><div><b>nginx_logformat.conf</b><br></div><span class="im"><div><font size="1">log_format main '$remote_addr - $remote_user [$time_local] "$request" '</font></div><div><font size="1"> '$status $body_bytes_sent "$host" "$http_referer" '</font></div><div><font size="1"> '"$http_user_agent" "$http_x_forwarded_for" '</font></div><div><font size="1"> '"$upstream_cache_status" "$request_length" '</font></div><div><font size="1"> '"$request_time" "$upstream_response_time" '</font></div><div><font size="1"> '"$pipe" "$bytes_sent" "$http_pragma" '</font></div><div><font size="1"> '"$http_cache_control" "{external_ip}" "{instance_name}" '</font></div><div><font size="1"> '"$scheme" "$upstream_status"<font color="#ff0000"> "cachestatus_map:$cachestatus_user_agent" '</font></font></div><div><font size="1"> <font color="#ff0000"> '"wordpress_key_map:$wordpress_key"'</font>;</font></div><div><br></div></span><div>And then I configure some maps like so:</div><div><b>nginx.conf</b></div><div> <span style="color:rgb(0,0,0);font-family:arial;white-space:pre-wrap;line-height:1.38;background-color:transparent">http {</span></div><span class="im"><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-family:arial;color:rgb(0,0,0);vertical-align:baseline;white-space:pre-wrap;background-color:transparent"> limit_req_zone $wordpress_key zone=wordpress_host:1m rate=1r/m;</span></p><br></span><p style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-family:arial;color:rgb(0,0,0);vertical-align:baseline;white-space:pre-wrap;background-color:transparent"><b> # Here's my initial map</b></span></p><span class="im"><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-family:arial;color:rgb(0,0,0);vertical-align:baseline;white-space:pre-wrap;background-color:transparent"> map $upstream_cache_status $cachestatus_user_agent {</span></p><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-family:arial;color:rgb(0,0,0);vertical-align:baseline;white-space:pre-wrap;background-color:transparent"> HIT $http_user_agent;</span></p><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-family:arial;color:rgb(0,0,0);vertical-align:baseline;white-space:pre-wrap;background-color:transparent"> EXPIRED $http_user_agent;</span></p><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-family:arial;color:rgb(0,0,0);vertical-align:baseline;white-space:pre-wrap;background-color:transparent"> - $http_user_agent;</span></p><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-family:arial;color:rgb(0,0,0);vertical-align:baseline;white-space:pre-wrap;background-color:transparent"> default "";</span></p><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-family:arial;color:rgb(0,0,0);vertical-align:baseline;white-space:pre-wrap;background-color:transparent"> }</span></p><br></span><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-family:arial;vertical-align:baseline;white-space:pre-wrap;background-color:transparent"> </span><span style="font-family:arial;vertical-align:baseline;white-space:pre-wrap;background-color:transparent"> <b># Successful case, because it starts with a non-mapped var</b></span></p><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><font color="#ff0000"><span style="line-height:1.38;font-family:arial;vertical-align:baseline;white-space:pre-wrap;background-color:transparent"> map $http_user_agent $wordpress_key</span><span style="line-height:1.38;font-family:arial;vertical-align:baseline;white-space:pre-wrap;background-color:transparent"> {</span></font></p><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="line-height:1.38;font-family:arial;color:rgb(0,0,0);vertical-align:baseline;white-space:pre-wrap;background-color:transparent"></span></p><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="line-height:17.94px;font-family:arial;vertical-align:baseline;white-space:pre-wrap;background-color:transparent"> </span><span style="line-height:17.94px;font-family:arial;vertical-align:baseline;white-space:pre-wrap;background-color:transparent"> <b># Failure case, because it starts with a mapped var</b></span><br></p><span class="im"><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-family:arial;vertical-align:baseline;white-space:pre-wrap;background-color:transparent"><font color="#ff0000"> map $cachestatus_user_agent $wordpress_key {</font></span></p><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-family:arial;color:rgb(0,0,0);vertical-align:baseline;white-space:pre-wrap;background-color:transparent"> ~(WordPress) $host;</span></p><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-family:arial;color:rgb(0,0,0);vertical-align:baseline;white-space:pre-wrap;background-color:transparent"> default "";</span></p><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-family:arial;color:rgb(0,0,0);vertical-align:baseline;white-space:pre-wrap;background-color:transparent"> }</span></p><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-family:arial;color:rgb(0,0,0);vertical-align:baseline;white-space:pre-wrap;background-color:transparent"> </span></p></span><p style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><font face="arial"><span style="white-space:pre-wrap">We can see the results below; in the successful case, we see both cachestatus_map and wordpress_key_map have the expected values:</span></font></p><div> </div><div><b>Access.log:</b></div><span class="im"><span style="line-height:1.38;font-family:arial;vertical-align:baseline;white-space:pre-wrap;background-color:transparent">127.0.0.1 - - [13/Jul/2016:16:21:49 -0400] "HEAD / HTTP/1.1" 200 0 "<a href="http://www.linna-test.com/" target="_blank">www.linna-test.com</a>" "-" "WordPress/2.1.1" "-" </span><span style="line-height:1.38;font-family:arial;vertical-align:baseline;white-space:pre-wrap;background-color:transparent"><font color="#ff0000">"HIT"</font></span><span style="line-height:1.38;font-family:arial;vertical-align:baseline;white-space:pre-wrap;background-color:transparent"> "87" "0.000" "-" "." "293" "-" "-" "{external_ip}" "{instance_name}" "http" "-"</span><span style="line-height:1.38;font-family:arial;vertical-align:baseline;white-space:pre-wrap;background-color:transparent"><font color="#ff0000"> "cachestatus_map:WordPress/2.1.1" "wordpress_key_map:<a href="http://www.linna-test.com/" target="_blank">www.linna-test.com</a>"</font></span><br></span><div><div><span style="font-family:arial;color:rgb(0,0,0);vertical-align:baseline;white-space:pre-wrap;background-color:transparent"><br></span></div>In the failure case, neither value matches. This is especially weird, because the first map didn't even change between the two cases.</div><div><br><div><span style="vertical-align:baseline"><p dir="ltr" style="font-family:arial;white-space:pre-wrap;color:rgb(0,0,0);line-height:1.38;margin-top:0pt;margin-bottom:0pt;background-color:transparent"><span style="vertical-align:baseline;background-color:transparent"><b style="line-height:1.5;font-family:sans-serif;white-space:normal;background-color:transparent">Access.log:</b></span></p><span class="im"><p dir="ltr" style="font-size:12.8px;font-family:arial;white-space:pre-wrap;color:rgb(0,0,0);line-height:1.38;margin-top:0pt;margin-bottom:0pt;background-color:transparent"><font color="#000000" style="line-height:1.38;background-color:transparent">127.0.0.1 - - [13/Jul/2016:16:27:32 -0400] "HEAD / HTTP/1.1" 200 0 "<a href="http://www.linna-test.com/" target="_blank">www.linna-test.com</a>" "-" "WordPress/2.1.1" "-"</font><font color="#ff0000" style="line-height:1.38;background-color:transparent"> "HIT" </font><font color="#000000" style="line-height:1.38;background-color:transparent">"87" "0.000" "-" "." "293" "-" "-" "{external_ip}" "{instance_name}" "http" "-" </font><font color="#ff0000" style="line-height:1.38;background-color:transparent">"cachestatus_map:" "wordpress_key_map:"</font><br></p><div><font color="#ff0000" style="line-height:1.38;background-color:transparent"><br></font></div><div><font style="line-height:1.38;background-color:transparent" color="#000000"><br></font></div><div><span style="line-height:17.94px"><font color="#000000">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 $</font></span><span style="color:rgb(0,0,0);line-height:17.94px">post_limited_binary_remote_addr were printed out when I log them.</span></div><div><div><span style="line-height:17.94px"><font color="#000000"> limit_req_zone $post_limited_binary_remote_addr zone=post_ip:1m rate=1r/m;</font></span></div><div><span style="line-height:17.94px"><font color="#000000"> map $request_method </font><font color="#ff0000">$post_remote_addr</font><font color="#000000"> {</font></span></div><div><span style="line-height:17.94px"><font color="#000000"> POST $remote_addr;</font></span></div><div><span style="line-height:17.94px"><font color="#000000"> default "";</font></span></div><div><span style="line-height:17.94px"><font color="#000000"> }</font></span></div><div><span style="line-height:17.94px"><font color="#000000"> map</font><font color="#ff0000"> $post_remote_addr</font><font color="#000000"> $post_limited_binary_remote_addr {</font></span></div><div><span style="line-height:17.94px"><font color="#000000"> "" "";</font></span></div><div><span style="line-height:17.94px"><font color="#000000"> default $binary_remote_addr;</font></span></div><div><span style="line-height:17.94px"><font color="#000000"> }</font></span></div><div style="color:rgb(255,0,0);line-height:17.94px"><br></div></div><div style="line-height:17.94px"><font color="#000000">It seems only $upstream_cache_status has this issue,</font><span style="color:rgb(255,0,0)"> <span style="font-size:12.8px;line-height:normal;color:rgb(34,34,34)">and I searched around a bit and couldn't find any public issues related to this. Does anyone have any thoughts on this?</span></span></div><div style="line-height:17.94px"><span style="color:rgb(255,0,0)"><span style="font-size:12.8px;line-height:normal;color:rgb(34,34,34)"><br></span></span></div><div style="line-height:17.94px"><span style="color:rgb(255,0,0)"><span style="font-size:12.8px;line-height:normal;color:rgb(34,34,34)">Thanks!</span></span></div><div style="line-height:17.94px"><span style="color:rgb(255,0,0)"><span style="font-size:12.8px;line-height:normal;color:rgb(34,34,34)">~Linna</span></span></div></span></span></div></div></div></div></div></div></div>
</div>