personium / ansible

Ansible files to set up a Personium unit.
Apache License 2.0
12 stars 15 forks source link

X-Personium-RequestKey header output in nginx logs #89

Closed shimono closed 5 years ago

shimono commented 5 years ago

Overview

Currently "X-Personium-RequestKey" request header value is only written in the following log files.

and not written in the nginx logs, which is making log analysis difficult.

By including "X-Personium-RequestKey" request header value in the nginx log settings in our ansible file distribution, such difficulties will be removed.

How

Update nginx.conf file in the ansible playbook and change its log_format item.

see https://github.com/personium/ansible/blob/master/1-server_unit/resource/web/opt/nginx/conf/nginx.conf#L40 https://siguniang.wordpress.com/2013/10/08/logging-request-response-headers-with-nginx/

tochi-y commented 5 years ago

Refer the link below. https://did2memo.net/2017/05/06/nginx-http-header-variables/

tochi-y commented 5 years ago

I added '[$http_x_personium_requestkey] ' to nginx.conf.

    log_format combined2    '$remote_addr - $remote_user [$time_local] '
                            '[$http_x_personium_version] '
+                            '[$http_x_personium_requestkey] '
                            '"$request" $status $body_bytes_sent '
                            '"$http_referer" "$http_user_agent" '
                            '"$ssl_cipher" "$ssl_protocol" '
                            '$request_time $upstream_response_time';

Then, call API as below.

$ curl -H 'X-Personium-RequestKey: MyRequestKey' localhost

The log is written as below.

127.0.0.1 - - [16/Jul/2019:12:24:31 +0900] [-] [MyRequestKey] "GET / HTTP/1.1" 200 73 "-" "curl/7.51.0" "-" "-" 0.020 0.020