Nginx未知指令" if($ http_user_agent"

时间:2014-10-01 14:29:26

标签: nginx

当用户代理标头具有特定值时,我尝试返回503状态代码。我尝试了外部和内部的位置块。但是当我重新加载这个配置nginx failes重新加载时:

upstream api{
    server 127.0.0.1:1336;
}

# the nginx server instance
server {
    listen 0.0.0.0:80;
    server_name api.project.com;

   # if($http_user_agent = "android") {
   #     return 503;
   # }

    # pass the request to the node.js server with the correct headers
    location / {

     # if($http_user_agent = "android") {
     #   return 503;
     # }

      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header Host $http_host;
      proxy_set_header X-NginX-Proxy true;

      proxy_pass http://api/;
      proxy_redirect off;
    }
}

任何想法都错了吗?我使用的是nginx / 1.4.7

来自syslog:

nginx: [emerg] unknown directive "if($http_user_agent"

1 个答案:

答案 0 :(得分:7)

在if和(。之间添加一个空格应该可以做到!