amazon-web-services – 如何阻止nginx记录Amazon Route 53运行状况检查请求?

前端之家收集整理的这篇文章主要介绍了amazon-web-services – 如何阻止nginx记录Amazon Route 53运行状况检查请求?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

目前,我的AWS运行状况检查正在无情地击中我的服务器:

...
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运行状况检查服务”的用户代理记录任何请求.

我目前的尝试如下:

# 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运行状况检查时,我的日志会继续被这些请求所淹没.

关于我在哪里做错的任何想法?

谢谢

最佳答案
事实证明我的健康检查设置为打到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;

无论如何干杯

原文链接:https://www.f2er.com/nginx/434473.html

猜你在找的Nginx相关文章