title: httpd mod_wsgi docker logs
body: <p>I have a python application that's running with the mod_wsgi module in httpd version 2.4.6 (CentOS). The application is then behind a firewall that is configured to insert X-Forwarded-For. In the docker logs, it shows the IP address of the Load Balancer instead of the true source IP. I found some documentation to adjust the httpd log format and I set the following in my httpd.conf:</p>
  <pre><code>    LogFormat &quot;%h %l %u %t \&quot;%r\&quot; %&gt;s %b \&quot;%{Referer}i\&quot; \&quot;%{User-Agent}i\&quot;&quot; combined
      LogFormat &quot;%{X-Forwarded-For}i %l %u %t \&quot;%r\&quot; %&gt;s %b \&quot;%{Referer}i\&quot; \&quot;%{User-Agent}i\&quot;&quot; proxy
      SetEnvIf X-Forwarded-For &quot;^.*\..*\..*\..*&quot; forwarded
      CustomLog &quot;logs/access_log&quot; combined env=!forwarded
      CustomLog &quot;logs/access_log&quot; proxy env=forwarded
  
  </code></pre>
  <p>And that works perfectly fine for the log file at /var/log/httpd/access_log, but it doesn't change the IP or format in the docker logs. To run the python application, I'm using the following command: <code>exec /usr/sbin/apachectl -DFOREGROUND</code> and my httpd vhost configuration looks like this:</p>
  <pre><code>listen 5000
  
  ServerName dagroup.sonicautomotive.com
  WSGISocketPrefix /var/run/wsgi
  ErrorLog /dev/stderr
  TransferLog /dev/stdout
  
  &lt;VirtualHost *:5000&gt;
          ServerAlias / /var/www/application
          SSLEngine on
          SSLProxyEngine on
          SSLCertificateFile /run/secrets/ssl_cert
          SSLCertificateKeyFile /run/secrets/ssl_key
          LoadModule wsgi_module &quot;/opt/application/lib/python3.8/site-packages/mod_wsgi/server/mod_wsgi-py38.cpython-38-x86_64-linux-gnu.so&quot;
          WSGIPassAuthorization On
          WSGIDaemonProcess application user=svcPython group=svcPython home=/home/svcPython threads=4
          WSGIScriptAlias / /var/www/application/application.wsgi
  
          &lt;Directory /var/www/application&gt;
                  WSGIProcessGroup application
                  WSGIApplicationGroup %{GLOBAL}
                  WSGIScriptReloading On
                  Require all granted
          &lt;/Directory&gt;
  &lt;/VirtualHost&gt;
  </code></pre>
  <p>Any idea how I can change the format of the docker logs (the logs you see when you run <code>docker logs &lt;container&gt;</code>)? The docker logs will also need to still include the output from the python application. (IE, if there is a print statement in the code, that still needs to appear in the docker logs). There also can't be any duplicated requests as I'm using the logs to track the usage of the application.</p>
  <p>Thank you!</p>
  <p>Edit:
  I also tried to add <code>ln -sf /proc/self/fd/1 /var/log/httpd/access_log</code> to the Dockerfile and that worked, but it caused duplicate entries to the docker log. Every time I made a single request, it would show me the request from the access_log and the default method.</p>