《 Nginx 配置 web 项目》
log_format json_combined escape=json
'{"serverName":"$server_name","remoteAddr":"$remote_addr","remoteUser":"$remote_user","timeLocal":"$time_l
ocal","request":"$request","reqBody":"$request_body",'
'"status":"$status","bodyBytesSent":"$body_bytes_sent","httpReferer":"$http_referer",'
'"httpUserAgent":"$http_user_agent","httpXForwardedFor":"$http_x_forwarded_for",'
"requestTime":"$request_time","upstreamResponseTime":"$upstream_respon
se_time","respBody":"$resp_body"}';
access_log logs/accessguo.log json_combined;
注:escape=json 部分配置可解决中文变 16 进制问题,需要 nginx 版本 1.11.8 以上
location1
location /jrebot {
rewrite ^/(.*)$ /$1 break;
root html;
index index.html index.htm;
proxy_pass
http://172.10.14.13:8081/jrebot;
proxy_set_header Host $host:$server_port;
proxy_redirect
http://192.168.220.135/ http://192.168.220.135:82/jrebot/;
proxy_set_header X-Real-IP $remote_addr:82;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Request-Url $request_uri:82;
proxy_next_upstream error timeout invalid_header http_500 http_502 http_503
http_504 http_404;
subs_filter 'href="/' 'href="/jrebot/';
subs_filter 'src="/' 'src="/jrebot/';
lua_need_request_body on;
body_filter_by_lua '
local resp_body = ngx.arg[1]
ngx.ctx.buffered = (ngx.ctx.buffered or"") .. resp_body
if ngx.arg[2] then ngx.var.resp_body = ngx.ctx.buffered
end ';
}
Proxy redirect 属性用来修改重定向报文的 location 字段
Subs_filter 提供了类似的报文数据替换功能,该模块默认不会安装,需要在编译 nginx 时添加--with-http_sub_module 参数 。参考:
https://www.cnblogs.com/fanzhidongyzby/p/5194895.html
响应日志可正常