docker-library / httpd

Docker Official Image packaging for Apache HTTP Server
https://httpd.apache.org
Apache License 2.0
310 stars 345 forks source link

combined format unavailable #211

Closed rumski20 closed 2 years ago

rumski20 commented 2 years ago

I am trying to get Apache to output using the combined format for my access log.

In my httpd.conf file I have this configuration for access logging:

<IfModule log_config_module>
    #
    # The following directives define some format nicknames for use with
    # a CustomLog directive (see below).
    #
    LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
    LogFormat "%h %l %u %t \"%r\" %>s %b" common

    <IfModule logio_module>
      # You need to enable mod_logio.c to use %I and %O
      LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
    </IfModule>

    #
    # The location and format of the access logfile (Common Logfile Format).
    # If you do not define any access logfiles within a <VirtualHost>
    # container, they will be logged here.  Contrariwise, if you *do*
    # define per-<VirtualHost> access logfiles, transactions will be
    # logged therein and *not* in this file.
    #
    #CustomLog /proc/self/fd/1 common
    #CustomLog /var/log/apache2/access.log common

    #
    # If you prefer a logfile with access, agent, and referer information
    # (Combined Logfile Format) you can use the following directive.
    #
    CustomLog /var/log/apache2/access.log combined
</IfModule>

I believe it's unchanged from the defaults.

However, when I run docker logs <apache-container> I don't get the referer or user-agent information in the log entries (I also get duplicate lines for each request, but that's probably a separate issue).

What do I need to do to get that information output in the log entries?

Thanks.

tianon commented 2 years ago

When you specify /var/log/apache2/access.log, you end up with your logs going to a file inside the container -- here's the relevant CustomLog line from the image:

$ docker run --rm httpd grep '  CustomLog' conf/httpd.conf
    CustomLog /proc/self/fd/1 common

If you want to access the logs via docker logs, you'll want to replicate this so the logs go to the container's stdout instead of to a file.

rumski20 commented 2 years ago

Okay, thank you for posting that code. It helped me dig in a little deeper.

I know this might qualify as a separate issue, but my ultimate goal is to have the apache container write logs to files on the host using the combined format.

To this end I cloned the repo and commented out the lines that I thought were sending logs to stdout. And then I specified a bind mount for where I thought the container would be writing the logs, with the intention of being able to access these files on the host:

volumes:
      # log files
      - /path/on/host/apache_logs:/var/log/apache2

However, when I run the code you posted above on my image, I get the following output: CustomLog "logs/access_log" common

I don't know where this configuration comes from. And when I remote into the container I can't find any directory or file named access_logs.
The only logs directory is at /usr/local/apache2/logs. And it only contains the httpd.pid file.

Thanks for any guidance you can provide.

tianon commented 2 years ago

I would suggest trying a dedicated support forum, such as the Docker Community Forums, the Docker Community Slack, or Stack Overflow for more help debugging the details of what's going wrong here.

If you want to completely disable our logging changes, you'll want to remove all three of these lines:

https://github.com/docker-library/httpd/blob/a7acc047c8970e0502f4c6b577775f840f1f99b6/2.4/Dockerfile#L205-L207

(Or revert them in your own configuration, which would allow you to avoid compiling httpd from source.)