title: How to log http request body from nginx docker image?
body: <p>I'm having a docker image with nginx.</p>
  
  <p>I would like to log incoming requests.</p>
  
  <p>My docker-compose file:</p>
  
  <pre><code>nginx:
    container_name: my-nginx
  image: nginx
  ports:
    - "80:80"
    - "443:443"
  volumes:
    - ./nginx.conf:/etc/nginx/conf.d/default.conf
    - ./access.log:/var/log/nginx/test.com.access.log
  </code></pre>
  
  <p>My nginx config:</p>
  
  <pre><code>server {
   listen 80;
   listen 443 default_server ssl;
   access_log /var/log/nginx/test.com.access.log;
  
   location / {
    proxy_pass http://myapp:8080;
    proxy_buffering off;
   }
  }
  </code></pre>
  
  <p>When I try to replace <code>access_log</code> directive with following config:</p>
  
  <pre><code>log_format testlog '$remote_addr - $remote_user [$time_local] '
                     '"$request" $status $bytes_sent '
                     '"$http_referer" "$http_user_agent" "$request_body"';
  access_log /var/log/nginx/test.com.access.log testlog;
  </code></pre>
  
  <p>I'm getting:</p>
  
  <pre><code>nginx-reverse-proxy | 2018/04/06 11:50:00 [emerg] 1#1: "log_format" directive is not allowed here in /etc/nginx/conf.d/default.conf:10
  nginx-reverse-proxy | nginx: [emerg] "log_format" directive is not allowed here in /etc/nginx/conf.d/default.conf:10
  </code></pre>