Help us understand the problem. What is going on with this article?

nginxのTCPロードバランサーでロギング

More than 3 years have passed since last update.

通常nginxでアクセスログを吐くにはaccess_logディレクティブを利用するのだけど、streamモジュールによるTCPロードバランサーだとこのディレクティブが使えない。公式ドキュメントにもあるようにaccess_logディレクティブを利用できるのはhttp, server, location, if in location, limit_exceptコンテキストに限られる。(nginxのTCPロードバランサーの設定はstreamコンテキストに記述する。)

# 
# access_log is available in the contexts below
# 
# http, server, location, if in location, limit_except
# 
access_log /var/log/nginx/access.log;

というわけでaccess_logは利用できないのでかわりにerror_logを使う。ログレベルはinfo以上じゃないと出力されない。

stream {
    error_log /var/log/nginx/stream.log info;
}

出力はこんな感じ。

2016/02/29 11:38:16 [info] 76796#0: *4 client 127.0.0.1:63501 connected to 0.0.0.0:9999
2016/02/29 11:38:16 [info] 76796#0: *4 proxy 127.0.0.1:63502 connected to 127.0.0.1:9001
2016/02/29 11:38:16 [info] 76796#0: *4 client disconnected, bytes from/to client:78/171, bytes from/to upstream:171/78

参考

access_log in stream context

cubicdaiya
Tech Lead, Network
mercari
フリマアプリ「メルカリ」を、グローバルで開発しています。
https://tech.mercari.com/
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした