---
title: "5-2　POSTデータ出力設定（Nginx）"
canonical: "https://manual.shadan-kun.com/space/KSK2INST/13992040/5-2%E3%80%80POST%E3%83%87%E3%83%BC%E3%82%BF%E5%87%BA%E5%8A%9B%E8%A8%AD%E5%AE%9A%EF%BC%88Nginx%EF%BC%89"
format: markdown
---
Nginx環境ではnginx.confのlog_format ディレクティブ内に`$request_body` を追加することで、POSTデータのログ出力が可能です。

> ⚠️ **注意**
> ⚠️ 
> ⚠️ - ミドルウェアの設定内容についてはサポート対象外です。詳細はサービス提供元のドキュメント等をご確認ください。

`設定ファイル：nginx.conf`

```
# $request_bodyを追加
log_format post '$remote_addr - $remote_user [$time_local] "$request"'
   ' $status $body_bytes_sent "$http_referer"'
   '"$http_user_agent" "$http_content_type" postdata[$request_body]';
   
# log_format の名称(下記例では「post」)を追加
access_log /var/log/nginx/access.log post;
```


#### Modsecurity遮断方式の場合（追加手順）

|  |
| --- |
| 【Modsecurity遮断構成例（中間機器あり）】  
クライアント[203.0.113.100] -> 中間機器[192.168.0.1] -> Webサーバ（Apache） |

上記構成の場合、クライアントIPアドレスを取得かつPOSTデータを出力するようにWebサーバのログフォーマットの変更を行います。

`設定ファイル：nginx.conf`

```
# $request_bodyを追加
log_format  main  '$http_x_forwarded_for $remote_addr - $remote_user [$time_local] "$request" '
                  '$status $body_bytes_sent "$http_referer" '
                  '"$http_user_agent" "$http_content_type" postdata[$request_body]';

# log_format の名称(下記例では「post」)を追加
access_log /var/log/nginx/access.log post;
```