nginx 日志打印请求头信息_nginx 打印请求头-CSDN博客
参数配置说明
underscores_in_headers on:nginx是支持读取非nginx标准的用户自定义header的,但是需要在http或者server下开启header的下划线支持:
比如我们自定义header为wx_unionid,获取该header时需要这样:$http_wx_unionid(一律采用小写,而且前面多了个http_)
如果需要把自定义header传递到下一个nginx:
1.如果是在nginx中自定义采用proxy_set_header X_CUSTOM_HEADER $http_host;
2.如果是在用户请求时自定义的header,例如curl –head -H “X_CUSTOM_HEADER: foo” http://domain.com/api/test,则需要通过proxy_pass_header X_CUSTOM_HEADER来传递
发现nginx转发的时候,似乎把在请求头中自定义的字段弄丢了
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_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Original-Header $http_X_Original_Header;
# proxy_set_header X_Gzmetro_uc_online $http_host;
proxy_pass_header Gzmetro_uc_online;
log_format custom_log '{"@timestamp": "$time_iso8601", '
'"connection": "$connection", '
'"version": "$http_version", '
'"remote_addr": "$remote_addr", '
'"remote_user": "$remote_user", '
'"request_method": "$request_method", '
'"request_uri": "$request_uri", '
'"request_length": "$request_length", '
'"server_protocol": "$server_protocol", '
'"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", '
'"upstream_addr": "$upstream_addr", '
'"gzmetro_uc_online": "$http_gzmetro_uc_online", '
'"request_time": "$request_time"}';
欢迎来撩 : 汇总all