步骤
-
使用ansible用户登录反向代理服务器
cd /etc/nginx/
-
修改配置文件nginx.conf
sudo vi nginx.conf
将
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 /var/log/nginx/access.log main;
改为
log_format json ‘{"request_id": "$request_id",‘
‘"remote_addr": "$remote_addr",‘
‘"time_iso8601": "$time_iso8601",‘
‘"request": "$request",‘
‘"status": "$status",‘
‘"body_bytes_sent": "$body_bytes_sent",‘
‘"http_referer": "$http_referer",‘
‘"http_user_agent": "$http_user_agent",‘
‘"http_x_forwarded_for": "$http_x_forwarded_for",‘
‘"request_time": "$request_time",‘
‘"upstream_response_time": "$upstream_response_time",‘
‘"upstream_addr": "$upstream_addr",‘
‘"upstream_connect_time": "$upstream_connect_time",‘
‘"upstream_status": "$upstream_status" }‘;
?
access_log /var/log/nginx/access.log json;
-
重新加载nginx
sudo nginx -t
?
sudo nginx -s reload