这是一个nginxconfiguration
server { listen $PORT; location ~ ^/documents/(.*)$ { proxy_pass http://127.0.0.1:5000/$1; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } location = /favicon.ico { return 204; access_log off; log_not_found off; } }
有两种使用情况的url /documents/ :
POST到/documents/进行一些处理或
AWS ELB使用GET /documents/ping作为运行状况检查
在cloudwatch日志中,我得到了一堆ping条目
问nginx不loggingping的最简单方法是什么?
这是一个简单的方法 – 添加这个位置块。
location ~ /documents/ping { proxy_pass http://127.0.0.1:5000/$1; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; access_log off; log_not_found off; }
可能有更干净的方法。 一个是将这两个块的共享内容定义为一个文件并包含它,但是对于一次性我不会打扰。
注 – 除非你不能帮助,否则不要使用if语句 。
更新
如果你想做一个包括做这样的事情
location ~ ^/documents/(.*)$ { include /path/to/fragment.conf; } location /documents/ping { include /path/to/fragment.conf; access_log off; log_not_found off; }
在文件fragment.conf中
proxy_pass http://127.0.0.1:5000/$1; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
同意〜没有必要,但我不认为这也会伤害。