With nginx.conf including the following
location /beta/ {
proxy_pass http://otherhost/;
}
then both of the following retrievals work:
curl -H 'User-Agent: Mozilla' http://localhost/beta/admin.htmlcurl -H 'User-Agent: iPhone' http://localhost/beta/admin.html
They both retrieve http://otherhost/admin.html
When I change nginx.conf to read:
location /beta/ {
if ($http_user_agent ~ iPhone ) {
}
proxy_pass http://otherhost/;
}
Then curl -H 'User-Agent: Mozilla' http://localhost/beta/admin.html continues to work but
curl -H 'User-Agent: iPhone' http://localhost/beta/admin.html gives a 404 and otherhost complains that it doesn’t have a file called beta/admin.html. This happens whether if is empty or not.
Huh?
You’re getting bit by a known problem: If is evil in nginx, meaning avoid
if-blocks insidelocation-blocks if at all posible (the link explains why and how)