'httpd mod_wsgi docker logs

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:

    LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
    LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" proxy
    SetEnvIf X-Forwarded-For "^.*\..*\..*\..*" forwarded
    CustomLog "logs/access_log" combined env=!forwarded
    CustomLog "logs/access_log" proxy env=forwarded

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: exec /usr/sbin/apachectl -DFOREGROUND and my httpd vhost configuration looks like this:

listen 5000

ServerName dagroup.sonicautomotive.com
WSGISocketPrefix /var/run/wsgi
ErrorLog /dev/stderr
TransferLog /dev/stdout

<VirtualHost *:5000>
        ServerAlias / /var/www/application
        SSLEngine on
        SSLProxyEngine on
        SSLCertificateFile /run/secrets/ssl_cert
        SSLCertificateKeyFile /run/secrets/ssl_key
        LoadModule wsgi_module "/opt/application/lib/python3.8/site-packages/mod_wsgi/server/mod_wsgi-py38.cpython-38-x86_64-linux-gnu.so"
        WSGIPassAuthorization On
        WSGIDaemonProcess application user=svcPython group=svcPython home=/home/svcPython threads=4
        WSGIScriptAlias / /var/www/application/application.wsgi

        <Directory /var/www/application>
                WSGIProcessGroup application
                WSGIApplicationGroup %{GLOBAL}
                WSGIScriptReloading On
                Require all granted
        </Directory>
</VirtualHost>

Any idea how I can change the format of the docker logs (the logs you see when you run docker logs <container>)? 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.

Thank you!

Edit: I also tried to add ln -sf /proc/self/fd/1 /var/log/httpd/access_log 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.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source