user www www;
worker_processes auto;
error_log /home/wwwlogs/openresty_nginx_error.log crit;
pid /usr/local/openresty/nginx/logs/nginx.pid;
worker_rlimit_nofile 51200;
events
{
use epoll;
worker_connections 51200;
multi_accept on;
}
http
{
include mime.types;
default_type 'text/html; charset=utf-8';
sendfile on;
tcp_nopush on;
keepalive_timeout 60;
tcp_nodelay on;
server_tokens off;
access_log off;
log_format app '{"ip":"$remote_addr","request":"$request","resp_body":"$resp_body"}';
log_escape_non_ascii off;
server
{
listen 6640;
index index.html index.htm index.php default.html default.htm default.php;
root /opt/webroot/platform_pricing/api/public;
location / {
try_files $uri $uri/ /index.php$is_args$query_string;
}
location ~ [^/]\.php(/|$)
{
try_files $uri =404;
fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_index index.php;
include fastcgi.conf;
}
set $resp_body "";
lua_need_request_body on;
body_filter_by_lua_file lua/log_by.lua;
access_log /opt/weblogs/platform/app.log app;
}
}
log_by.lua的内容如下:
local chunk, eof = ngx.arg[1], ngx.arg[2]
local buffered = ngx.ctx.buffered
if not buffered then
buffered = {}
ngx.ctx.buffered = buffered
end
if chunk ~= "" then
buffered[#buffered + 1] = chunk
ngx.arg[1] = nil
end
if eof then
local whole = table.concat(buffered)
ngx.ctx.buffered = nil
ngx.arg[1] = whole
ngx.var.resp_body = ngx.arg[1]
end
谢谢~