網上不少教程說是這樣作:html
if ($request_method = HEAD) { access_log off; }
試了以後是不行的,正確的作法以下:nginx
http { map $request_method $loggable { HEAD 0; OPTIONS 0; default 1; } log_format main '$remote_addr [$time_local] $request $status $body_bytes_sent $http_user_agent'; access_log /var/log/nginx/access.log main if=$loggable; }
這裏過濾掉了HEAD和OPTIONS請求spa
官方文檔地址:http://nginx.org/en/docs/http/ngx_http_log_module.htmlcode