Debian系統上的Nginx主要記錄兩種類型的日志:訪問日志(access_log)和錯誤日志(error_log)。這些日志對于統計、系統服務排錯和監控非常有幫助。
通過log_format
指令,可以自定義日志格式,以滿足特定的需求。
例如,以下是一個自定義的日志格式示例:
log_format custom '$remote_addr - $remote_user [$time_local] ' '"$request" $status $body_bytes_sent ' '"$http_referer" "$http_user_agent" "$http_x_forwarded_for"';
使用這個自定義格式,可以通過以下命令應用到訪問日志:
access_log /var/log/nginx/access.log custom;
訪問日志和錯誤日志的配置通常在Nginx的配置文件nginx.conf
中的http
模塊下進行。例如:
http {
access_log /var/log/nginx/access.log custom;
error_log /var/log/nginx/error.log;
...
}