小木兮子 2020-06-12
反向代理日志json
化
步骤
使用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
某些公司会墙特定网站,如果你有一个可访问的域名和服务器,就可以通过nginx反向代理来来解决这些问题。比如现在我们用mirror.example.com镜像www.baidu.com,以下是详细操作。