最近在配置本地nginx开发环境时,发现一个问题,当server段不指定access_log时,并且http段中也未指定任何access_log参数时,它会默认写到logs/access.log这个文件,也就是access_log默认值就是”logs/access.log”,而且是所有server的访问日志。但nginx网站上我并未找到此配置的默认值。
    如果我们不需要,在http段中加一行access_log off;然后在特定的server中配置自己想写入的日志。开发环境我默认不写日志,即不配置任何access_log,需要时才打开。
    nginx的http段中,设置access log:

    1. log_format main '$remote_addr - $remote_user [$time_local] "$request" '
    2. '$status $body_bytes_sent "$http_referer" '
    3. '"$http_user_agent" "$http_x_forwarded_for"';
    4. log_format gzip '$remote_addr - $remote_user [$time_local] "$request" '
    5. '$status $bytes_sent "$http_referer" '
    6. '"$http_user_agent" "$gzip_ratio"';
    7. log_format download '$remote_addr - $remote_user [$time_local] "$request" '
    8. '$status $bytes_sent "$http_referer" "$http_user_agent" '
    9. '"$http_range" "$sent_http_content_range"';
    10. #access_log logs/access.log main;
    11. access_log off;

    This entry was posted in Uncategorized and tagged access_log, nginx. Bookmark the permalink.