if-clause garbles variable content
marius
nginx-forum at nginx.us
Sat Dec 19 23:33:10 MSK 2009
I'd like to use a map in order to prevent various spiders from indexing documents, but I'm running into strange issues, which I can't explain (nginx 0.7.62 or 0.7.64):
root /tmp/test;
map $lookup $test_blacklist {
default "";
/aabbccddeeff/aabbccddeeff/2009/A/Pdf/20090101.pdf 1;
}
location ~* ^/aabbccddeeff(/.*) {
set $lookup "";
if ($http_user_agent ~ "Googlebot|Slurp|msnbot") {
# force lowercase "aabbccddeeff"
set $lookup /aabbccddeeff$1;
}
if ($test_blacklist != "") {
return 410;
}
charset iso-8859-1;
alias /tmp/test/aabbccddeeff$1;
}
When requesting a file from that map, the open() log points to a garbled path "/aabbccddeeffcddeeff" rather than the requested "/aabbccddeeff/aabbccddeeff":
31998#0: *1 "Googlebot|Slurp|msnbot" matches "Googlebot", client: 127.0.0.1, server: test, request: "HEAD /aabbccddeeff/aabbccddeeff/2009/A/Pdf/20090101.pdf HTTP/1.1", host: "test"
31998#0: *1 open() "/tmp/test/aabbccddeeffcddeeff/2009/A/Pdf/20090101.pdf" failed (2: No such file or directory), client: 127.0.0.1, server: test, request: "HEAD /aabbccddeeff/aabbccddeeff/2009/A/Pdf/20090101.pdf HTTP/1.1", host: "test"
What's more, if the user-agent isn't matched, the server sends a 301 redirect with an appended "/" rather than delivering the file:
HTTP/1.1 301 Moved Permanently
Location: http://test/aabbccddeeff/aabbccddeeff/2009/A/Pdf/20090101.pdf/
On the other hand, if I omit the $http_user_agent test, the server behaves as expected, by either delivering the file or returning a 410 status, dependning of the content of $lookup.
Am I doing something wrong?
Posted at Nginx Forum: http://forum.nginx.org/read.php?2,31950,31950#msg-31950
More information about the nginx
mailing list