Outputting Request Headers in Nginx Logs
nginx
2020-05-06 14:24 (6 years ago)
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;
}
Please rate this article (No signup or login required)
Currently unrated
The author runs the application development company Cyberneura.
We look forward to discussing your development needs.
We look forward to discussing your development needs.