How to add custom apache config
Closed this issue · 1 comments
Thijmen commented
Hi there,
I have a custom apache config that I add to the image:
ADD ./docker/apache/custom.conf /etc/apache2/docker.d/custom.conf
The contents of this file is;
LogFormat "{ \"time\":\"%t\", \"remoteIP\":\"%a\", \"host\":\"%V\", \"request\":\"%U\", \"query\":\"%q\", \"method\":\"%m\", \"status\":\"%>s\", \"userAgent\":\"%{User-agent}i\", \"referer\":\"%{Referer}i\", \"originalUri\": \"%{Plugin-Original-Uri}i\" }" combined
CustomLog ${APACHE_ACCESS_LOG} combined
However, I cannot see the json logs in the terminal when visiting a page. What can I do to achieve this?
shinsenter commented
Hello, thank you for asking the question.
To add your configs for Apache, you can copy your *.conf files into the /etc/apache2/sites-enabled/
directory of the container.
I tried testing with the following Dockerfile and confirmed the access log was able to output in a JSON-like format:
Dockerfile
FROM shinsenter/php:8.3-fpm-apache
RUN <<'EOF'
echo '
LogFormat "{ \"time\":\"%t\", \"remoteIP\":\"%a\", \"host\":\"%V\", \"request\":\"%U\", \"query\":\"%q\", \"method\":\"%m\", \"status\":\"%>s\", \"userAgent\":\"%{User-agent}i\", \"referer\":\"%{Referer}i\", \"originalUri\": \"%{Plugin-Original-Uri}i\" }" combined
CustomLog ${APACHE_ACCESS_LOG} combined
' >/etc/apache2/sites-enabled/custom-logging.conf
EOF
Access logs
[08-Feb-2024 01:15:47] NOTICE: fpm is running, pid 1883
[08-Feb-2024 01:15:47] NOTICE: ready to handle connections
[Thu Feb 08 01:15:47.825814 2024] [mpm_event:notice] [pid 1891:tid 281473448280096] AH00489: Apache/2.4.57 (Debian) OpenSSL/3.0.11 configured -- resuming normal operations
[Thu Feb 08 01:15:47.825887 2024] [core:notice] [pid 1891:tid 281473448280096] AH00094: Command line: 'apache2 -e error -D FOREGROUND'
[Thu Feb 08 01:15:52.773789 2024] [authz_core:error] [pid 1993:tid 281473184997664] [client 192.168.65.1:31134] AH01630: client denied by server configuration: /var/www/html/index.html
[Thu Feb 08 01:15:52.773853 2024] [authz_core:error] [pid 1993:tid 281473184997664] [client 192.168.65.1:31134] AH01630: client denied by server configuration: /var/www/html/index.htm
- - 08/Feb/2024:01:15:52 +0000 "GET /index.php" 200 localhost/ 0.020 2048 0.00% -
{ "time":"[08/Feb/2024:01:15:52 +0000]", "remoteIP":"192.168.65.1", "host":"localhost", "request":"/index.php", "query":"", "method":"GET", "status":"200", "userAgent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.4 Safari/605.1.15", "referer":"-", "originalUri": "-" }
Please let me know if you have any other questions or concerns - we're committed to making this a seamless process.
Best regards.