当用户代理标头具有特定值时,我尝试返回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;
}
}
Run Code Online (Sandbox Code Playgroud)
任何想法都错了吗?我使用的是nginx/1.4.7
来自syslog:
nginx: [emerg] unknown directive "if($http_user_agent"
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3837 次 |
| 最近记录: |