nginx 如果在server段写了access_log,再在http段写access_log,那么http段的access_log就不记录内容吗?
http段
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /home/logs/nginx/access.log main;
server 段
error_log /home/hosts_log/2_error.log notice;
access_log /home/hosts_log/2_access.log lu_access_log_1 buffer=32k;
每次重启后会生成空的/home/logs/nginx/access.log,但是无论怎么刷新页面,内容都是空。server段的配置就生效。
参考官方文档即可:
https://nginx.org/r/access_log
access_log 可以使用的范围:http, server, location, if in location, limit_except
比如这个配置:
请求最终匹配到哪个 {} block,这个 block 配置了 access_log,就会覆盖上一级的 access_log