nginx でリバースプロキシとログ出力の設定をする中でどうしてもわからずハマっています。
$request_bodyの内容をログに出力しているのですが、locationの中で$request_bodyを参照すると、ログに出力されなくなってしまうのです。
試したこと
以下が実際に試した設定です。
nginxはログのフォーマットとserverコンテキスト以外はデフォルトのままです。(コメントは除きました)
######nginx.conf
user www-data; worker_processes 4; pid /run/nginx.pid; events { worker_connections 768; } http { sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 65; types_hash_max_size 2048; include /etc/nginx/mime.types; default_type application/octet-stream; log_format test '$remote_addr [$time_local] "$request" ' '$status "$request_body"'; access_log /var/log/nginx/access.log test; error_log /var/log/nginx/error.log; gzip on; gzip_disable "msie6"; include /etc/nginx/conf.d/*.conf; include /etc/nginx/sites-enabled/*; client_body_buffer_size 2m; server { server_name 192.168.43.51; location / { proxy_pass http://192.168.43.52; } } }
192.168.43.51はwebサーバー(nginx)、
192.168.43.52はAPサーバーの想定です。
APサーバー内に以下のような簡単なフォームを作成して、POSTの動作を見ていました。
######test.html
html
1<html> 2<form action="http://192.168.43.51/" method="post"> 3 <div> 4 <label for="name">Name:</label> 5 <input type="text" id="name" name="user_name"> 6 </div> 7 <div> 8 <label for="mail">E-mail:</label> 9 <input type="email" id="mail" name="user_mail"> 10 </div> 11 <div class="button"> 12 <button type="submit">Send</button> 13 </div> 14</form> 15</html> 16
nginxのアクセスログには下記のように出力されました。
######access.log
192.168.43.1 [19/Jan/2019:16:26:14 +0000] "POST / HTTP/1.1" 200 "&user_name=&user_mail="
ここまでは想定通りでした。
ところが、locationコンテキストの中に以下の一文を入れると、ログに$request_bodyが出力されなくなってしまいました。
######nginx.conf
server { server_name 192.168.43.51; location / { set $test $request_body; # 追加 proxy_pass http://192.168.43.52; } } }
######access.log
192.168.43.1 [19/Jan/2019:16:27:06 +0000] "POST / HTTP/1.1" 200 "-"
$request_bodyを参照しただけのつもりなのですが、なぜこうなるのかがさっぱり分からず、、、お知恵を拝借したいです。
よろしくお願いします。
補足情報(FW/ツールのバージョンなど)
Ubuntu 14.04.5 LTS
nginx version: nginx/1.4.6 (Ubuntu)
あなたの回答
tips
プレビュー