ベーコンの裏

囲碁・ボドゲ・温泉を愛するフクロウのブログ

Nginxの設定メモ

リバースプロキシ時にホストを書き換えない

リバースプロキシしても、HTTP_HOSTをアクセス時のホストのままにする。

proxy_set_header Host $host;

アクセスログをTLSV形式にする

解析しやすい

log_format tlsv  "time:$time_local"
 "\thost:$remote_addr"
 "\tvhost:$host"
 "\tforwardedfor:$http_x_forwarded_for"
 "\treq:$request"
 "\tstatus:$status"
 "\tsize:$body_bytes_sent"
 "\treferer:$http_referer"
 "\tua:$http_user_agent"
 "\ttaken_sec:$request_time"
 "\tcache:$upstream_http_x_cache"
 "\truntime:$upstream_http_x_runtime"
 "\tupstream:$upstream_addr"
 "\tupstream_status:$upstream_status"
 "\trequest_length:$request_length"
 "\tbytes_sent:$bytes_sent"
 ;

PHPを使ってリクエストごとに解析する↓

https://gist.github.com/sunbacon/a4251d28921cd85c6e1ed40094e6987e