nginxにカスタムヘッダーのレスポンスを表示する
タイトルのようなことがやりたかった時に色々調べたでそれのメモ。
アプリは仮に下記のようなコードがあったとする
require 'sinatra' get '/' do status 200 headers \ “X-Unchi-Status" => ‘BuriBuri’ body "hello" end
GETでアクセスしてきたとき
- ステータスは200
- カスタムヘッダ
X-Unchi-Status
にBuriBuri
とセットして
と返す
これのカスタムヘッダ X-Unchi-Status
の結果をnginxのlogに流すにはnginx.conf 等に
sent_http_xxx
の xxx
の部分に自分で設定したカスタムヘッダを入れてあげる。
今回だと
log_format test ‘unchi-status:$sent_http_x_unchi_status` … access_log /var/log/access.log test;
みたいな感じに設定してあげれば。
すると
log に流れてくる。
快適なlog life を!!
参考ページ
http://nginx.org/en/docs/http/ngx_http_log_module.html
Header lines sent to a client have the prefix “sent_http_”, for example, $sent_http_content_range.
- 作者: Clement Nedelcu,長尾高弘
- 出版社/メーカー: アスキー・メディアワークス
- 発売日: 2011/04/21
- メディア: 大型本
- 購入: 2人 クリック: 714回
- この商品を含むブログ (23件) を見る