Outputting Request Headers in Nginx Logs

nginx
2020-05-06 23:24 (4 years ago) ytyng

log_format.conf

log_format header
  '[$time_local]\n'
  '$request\n'
  'request ------------\n'
  'remote_addr: $remote_addr\n'
  'remote_user: $remote_user\n'
  'request_time: $request_time\n'
  'host: $http_host\n'
  'referer: $http_referer\n'
  'accept_encoding: $http_accept_encoding\n'
  'accept_language: $http_accept_language\n'
  'user_agent: $http_user_agent\n'
  'x_forwarded_proto: $http_x_forwarded_proto\n'
  'x_forwarded_for: $http_x_forwarded_for\n'
  'x_forwarded_host: $http_x_forwarded_host\n'
  'x_real_ip: $http_x_real_ip\n'
  'response ------------\n'
  'status: $status\n'
  'size: $body_bytes_sent\n'
  'content_type: $sent_http_content_type\n';

Ansible Playbook YAML

- remote_user: ubuntu
  hosts: servers
  become: yes
  tasks:

    - copy:
      src: log_format.conf
      dest: /etc/nginx/conf.d/log_format.conf
      owner: root
      group: root
      mode: 0644

    - name: "Restart nginx"
      service:
      name: nginx
      state: restarted

Nginx Server Configuration

server {
  listen 80 default;
  ...
  access_log /var/log/nginx/torico-id-header.log header;
}
Currently unrated
The author runs the application development company Cyberneura.
We look forward to discussing your development needs.

Archive

2025
2024
2023
2022
2021
2020
2019
2018
2017
2016
2015
2014
2013
2012
2011