Skip to content

dmitry-j-mikhin/nginx-njs-log

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

nginx-njs-log

This is example docker image based on official nginx:1.26.2 stable image with support of full request(headers+body) and response(headers+body) logging using njs. For more details check:

Image can be executed with run.sh script:

$ ./run.sh

Send example request:

$ curl 127.0.0.1 -d "example request body payload"

Latest log record formatted with jq can be viewed with command docker logs --tail 1 nginx-njs-log | jq:

{
  "source": "nginx",
  "msec": 1690974762.229,
  "time_iso8601": "2023-08-02T11:12:42+00:00",
  "request_time": 0.001,
  "body_bytes_sent": 157,
  "bytes_sent": 314,
  "request_length": 171,
  "http_host": "127.0.0.1",
  "http_user_agent": "curl/7.68.0",
  "remote_addr": "172.17.0.1",
  "request_method": "POST",
  "request_uri": "/",
  "status": 405,
  "upstream_addr": "127.0.0.1:8080",
  "request_body_njs": "example request body payload",
  "response_body_njs": "<html>\r\n<head><title>405 Not Allowed</title></head>\r\n<body>\r\n<center><h1>405 Not Allowed</h1></center>\r\n<hr><center>nginx/1.26.2</center>\r\n</body>\r\n</html>\r\n",
  "request_headers_njs": {
    "Host": "127.0.0.1",
    "User-Agent": "curl/7.68.0",
    "Accept": "*/*",
    "Content-Length": "28",
    "Content-Type": "application/x-www-form-urlencoded"
  },
  "response_headers_njs": {
    "Content-Type": "text/html",
    "Content-Length": "157"
  }
}

Also logs can be sent to external syslog server:

$ SYSLOG_SRV="syslog:server=172.17.0.1:5514,facility=local7,tag=nginx,severity=info" ./run.sh

Syslog output using syslog2stdout:

$ ./syslog2stdout 5514
172.17.0.2:52961: local7.info: fafc6ae1c7f0 nginx: {"source": "nginx","msec": 1690981227.381,"time_iso8601": "2023-08-02T13:00:27+00:00","request_time": 0.001,"body_bytes_sent": 157,"bytes_sent": 314,"request_length": 171,"http_host": "127.0.0.1","http_user_agent": "curl/7.68.0","remote_addr": "172.17.0.1","request_method": "POST","request_uri": "/","status": 405,"upstream_addr": "127.0.0.1:8080","request_body_njs": "example request body payload","response_body_njs": "<html>\r\n<head><title>405 Not Allowed</title></head>\r\n<body>\r\n<center><h1>405 Not Allowed</h1></center>\r\n<hr><center>nginx/1.26.2</center>\r\n</body>\r\n</html>\r\n","request_headers_njs": {"Host":"127.0.0.1","User-Agent":"curl/7.68.0","Accept":"*/*","Content-Length":"28","Content-Type":"application/x-www-form-urlencoded"},"response_headers_njs": {"Content-Type":"text/html","Content-Length":"157"}}

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published