将 Apache 日志重定向到 STDOUT

Rit*_*esh 5 linux apache docker

我有一个在后台运行 apache 服务器的 docker 容器(apachectl start &),我通过CustomLog /dev/stdoutErrorLog /dev/stderr指令将日志定向到 STDOUT/STDERR 。

现在,当我调用包含 apache 启动命令 (apachectl start &) 的脚本时,我无法在控制台上查看日志。

但是,如果使用apachectl start -DFOREGROUND作为命令,我可以很好地看到控制台上的输出。

关于我们如何在后台运行的 apache 的控制台上获取日志的任何想法?

谢谢您的帮助

Gog*_*sch 5

如果您的容器运行主 Bash 脚本,您可以添加以下重定向:

sudo ln -sf /proc/$$/fd/1 /var/log/apache2/access.log
sudo ln -sf /proc/$$/fd/2 /var/log/apache2/error.log
Run Code Online (Sandbox Code Playgroud)

它将 Apache 输出重定向到当前 Bash 的 stdout/stderr。确保在创建符号链接后(重新)启动 Apache,否则 Apache 将看不到它。

如果 Apache 作为 systemd/init.d 服务运行就可以了。换句话说,Apache 不需要在 Bash 中运行。

对于我们来说,Docker 容器的目的是运行持续集成测试,因此我将这些行添加到我们的.gitlab-ci.yml文件中。

一些背景:每个进程都有自己的 stdout/stderr。Bash 的另一个实例不一定会连接到同一个 stdout/stderr。同样,如果 Apache 作为服务运行,OP 的 Apache 指令ErrorLog /dev/stderr会将其写入系统日志或日志。