2014-01-14 40 views
6

目前我的AWS健康检查是打我的服务器很无情:如何停止nginx的登录亚马逊路线53健康检查的要求?

... 
54.228.16.40 - - [14/Jan/2014:10:17:22 +0000] "GET/HTTP/1.1" 301 178 "-" "Amazon Route 53 Health Check Service" 
54.248.220.40 - - [14/Jan/2014:10:17:24 +0000] "GET/HTTP/1.1" 301 178 "-" "Amazon Route 53 Health Check Service" 
54.232.40.110 - - [14/Jan/2014:10:17:25 +0000] "GET/HTTP/1.1" 301 178 "-" "Amazon Route 53 Health Check Service" 
54.241.32.78 - - [14/Jan/2014:10:17:26 +0000] "GET/HTTP/1.1" 301 178 "-" "Amazon Route 53 Health Check Service" 
54.245.168.46 - - [14/Jan/2014:10:17:28 +0000] "GET/HTTP/1.1" 301 178 "-" "Amazon Route 53 Health Check Service" 
54.251.31.174 - - [14/Jan/2014:10:17:28 +0000] "GET/HTTP/1.1" 301 178 "-" "Amazon Route 53 Health Check Service" 
... 

我想Nginx的配置为无法登录与"Amazon Route 53 Health Check Service"用户代理的任何请求。

我当前的尝试看起来如下:

# default server for forwarding all requests over to main www domain 
server { 
    listen 80 default_server; 

    server_name _; 

    return 301 $scheme://www.example.com$request_uri; 
} 

# server configured to catch aws health check requests 
server { 
    listen 80; 
    server_name 12.345.67.89; 

    location/{ 
     if ($http_user_agent ~* 'Amazon Route 53 Health Check Service') { 
      access_log off; 
      return 200 'Service OK';  
     } 
    } 
} 

# actual application server 
server { 
    listen 80; 
    server_name www.example.com; 

    location/{ 
     ... 
    } 
} 

这对我来说很好,而事实上,当我CURL的健康检查,建立击中同一地址:

curl --user-agent "Amazon Route 53 Health Check Service" http://12.345.67.89:80/ 

我得到我所期望的:

Service OK 

而且我的要求在没有结束日志。

然而,我的日志继续当他们从实际AWS健康检查要由这些请求所淹没。

上,我做错了其中任何想法?

感谢

回答

1

所以,事实证明,我的健康检查的建立是为了打击example.com而非IP地址:我的坏。

为了记录在案,我通过添加$host变量,以我的日志格式(见行尾)发现了这个:

log_format debug_format '$remote_addr - $remote_user [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent" "$http_x_forwarded_for" host:"$host"'; 

access_log /var/log/nginx/access.log debug_format; 

干杯反正

+0

这不回答这个问题.. 。? –