1. vim /etc/nginx/nginx.conf (下面格式, Awstats 使用)
log_format new_log
'$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 new_log;
error_log /var/log/nginx/error.log;
2. 额外说明的是:“区分‘全局log配置’ 和 ‘局部log配置’ ”:
* 全局:
server { //这是server开始
listen 80;
server_name mysite.com;
….
…. 这里代表都是配置
….
} //这是server结束
log_format kinggoo.com ‘$remote_addr – $remote_user [$time_local] "$request" ‘
‘$status $body_bytes_sent "$http_referer" ‘
‘"$http_user_agent" "$http_x_forwarded_for"’;
access_log /data0/nginx/weblogs/access_blog.kinggoo.com.log kinggoo.com;
error_page 500 502 503 504 404 403 /50x.html;
* 局部:
log_format kinggoo.com ‘$remote_addr – $remote_user [$time_local] "$request" ‘
‘$status $body_bytes_sent "$http_referer" ‘
‘"$http_user_agent" "$http_x_forwarded_for"’;
server { //这是server开始
listen 80;
server_name mysite.com;
….
…. 这里代表都是配置
….access_log /data0/nginx/weblogs/access_blog.kinggoo.com.log kinggoo.com;
error_page 500 502 503 504 404 403 /50x.html;
} //这是server结束
3. 最后,检查nginx配置是否正确,然后重启载入nginx配置:
1. sudo nginx -t
2. sudo /etc/init.d/nginx reload