Nginx

211 阅读1分钟

log_format

# log_format定义
# 默认格式日志
log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                  '$status $body_bytes_sent "$http_referer" '
                  '"$http_user_agent" "$http_x_forwarded_for"';
# json格式的日志
log_format logJson '{"timestamp": "$time_local", '
                     '"fields": { '
                     '"remote_addr": "$remote_addr", '
                     '"remote_user": "$remote_user", '
                     '"body_bytes_sent": "$body_bytes_sent", '
                     '"request_time": "$request_time", '
                     '"status": "$status", '
                     '"request": "$request", '
                     '"request_method": "$request_method", '
                     '"http_referrer": "$http_referer", '
                     '"body_bytes_sent":"$body_bytes_sent", '
                     '"http_x_forwarded_for": "$http_x_forwarded_for", '
                     '"http_user_agent": "$http_user_agent" }}';
                     
# 设置日志文件 可以放入location,指定url记录日志
access_log  logs/access.log  main;
access_log logs/jsonData.log logJson;

location / {
	access_log logs/jsonData.log logJson;
    #root   html;
    #index  index.html index.htm;
	proxy_redirect off;
	proxy_set_header Host $host;
	proxy_set_header X-Real-IP $remote_addr;
	proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
	proxy_pass https://www.baidu.com;
}