<p>I need to implement logging for kubernetes ingress installation so all request will be logging with the following details:</p>

<ul>
<li>Request headers</li>
<li>Request body</li>
<li>Response headers</li>
<li>Response body</li>
</ul>

<p>I understand that I can edit <code>log_format</code> of nginx using <a href="https://github.com/kubernetes/ingress-nginx/blob/master/docs/user-guide/configmap.md" rel="nofollow noreferrer">ConfigMap</a>, however, for logging response body, I need to use lua (something like <a href="https://gist.github.com/morhekil/1ff0e902ed4de2adcb7a" rel="nofollow noreferrer">this</a>). </p>

<p>In this case, I should have possibility to add this lua code in every server section of nginx config. What is the most easy way to do it?</p>

<p>Thank you!</p>

<p>I think I found the solution. I need to use custom nginx template. In general, the steps should be as following:</p>

<ol>
<li>Obtain the <code>nginx.tmpl</code> from the ingress-nginx controller that is located at <code>/etc/nginx/template/nginx.tmpl</code></li>
<li>Edit it according to your needs</li>
<li>Map it using volumes</li>
</ol>

<p>The detailed instruction is located <a href="https://github.com/kubernetes/ingress-nginx/blob/master/docs/user-guide/custom-template.md" rel="nofollow noreferrer">here</a></p>
