2013-02-07 46 views
0

随着nginx.conf包括以下疯狂:IF子句打破LOCATION子句

 location /beta/ { 
     proxy_pass http://otherhost/; 
     } 

那么以下两个检索的工作:

  • curl -H 'User-Agent: Mozilla' http://localhost/beta/admin.html
  • curl -H 'User-Agent: iPhone' http://localhost/beta/admin.html

他们都找回http://otherhost/admin.html

当我改变nginx.conf阅读:

 location /beta/ { 
     if ($http_user_agent ~ iPhone) { 
     } 
     proxy_pass http://otherhost/; 
     } 

然后curl -H 'User-Agent: Mozilla' http://localhost/beta/admin.html继续工作,但 curl -H 'User-Agent: iPhone' http://localhost/beta/admin.html给出了404和OTHERHOST抱怨说,它没有一个叫beta/admin.html文件。无论if是否为空,都会发生这种情况。

咦?

回答

0

你被一个已知的问题得到位:If is evil in nginx,这意味着避免内部location -blocks if -blocks如果在所有更多钞票(链接解释了为什么以及如何)