配置

须要批改apache httpd加载配置文件httpd-info.conf

须要凋谢拜访server-infoserver-status的权限

docker实现

创立Dockerfile如下

FROM httpd:2.4-alpine# 启用httpd info 模块RUN sed -i "s|#Include conf/extra/httpd-info.conf|Include conf/extra/httpd-info.conf|g" /usr/local/apache2/conf/httpd.conf# 加载mod info 凋谢拜访server info 信息RUN sed -i "s|#LoadModule info_module modules/mod_info.so|LoadModule info_module modules/mod_info.so|g" /usr/local/apache2/conf/httpd.conf# 配置容许近程拜访,防止403谬误RUN sed -i "s/Require host .example.com/Order deny,allow/g" /usr/local/apache2/conf/extra/httpd-info.confRUN sed -i "s/Require ip 127/Allow from all/g" /usr/local/apache2/conf/extra/httpd-info.conf

创立compose.yaml

services:  apache:    container_name: demo-apache    image: demo-apache    build: .    restart: always    ports:      - "80:80"

构建镜像

$ docker compose build

服务启动

$ docker compose up -d

查看拜访配置信息

$ docker exec demo-apache cat /usr/local/apache2/conf/extra/httpd-info.conf....<Location /server-status>    SetHandler server-status    Order deny,allow    Allow from all</Location>....<Location /server-info>    SetHandler server-info    Order deny,allow    Allow from all</Location>

验证后果

浏览器拜访地址http://127.0.0.1/server-status获取服务状态信息

Apache Server Status for 127.0.0.1 (via 172.29.0.2)Server Version: Apache/2.4.55 (Unix)Server MPM: eventServer Built: Feb 11 2023 09:43:46Current Time: Monday, 20-Mar-2023 07:01:24Restart Time: Monday, 20-Mar-2023 07:00:29Parent Server Config. Generation: 1Parent Server MPM Generation: 0Server uptime: 54 secondsServer load: 0.75 0.88 0.92Total accesses: 2 - Total Traffic: 52 kB - Total Duration: 4CPU Usage: u.02 s.02 cu0 cs0 - .0741% CPU load.037 requests/sec - 986 B/second - 26.0 kB/request - 2 ms/request1 requests currently being processed, 99 idle workersSlot    PID    Stopping    Connections    Threads    Async connectionstotal    accepting    busy    idle    writing    keep-alive    closing0    8    no    0    yes    0    25    0    0    01    9    no    0    yes    0    25    0    0    02    10    no    0    yes    1    24    0    0    03    92    no    0    yes    0    25    0    0    0Sum    4    0    0         1    99    0    0    0___________________________________________________W________________________________________________............................................................................................................................................................................................................................................................................................................Scoreboard Key:"_" Waiting for Connection, "S" Starting up, "R" Reading Request,"W" Sending Reply, "K" Keepalive (read), "D" DNS Lookup,"C" Closing connection, "L" Logging, "G" Gracefully finishing,"I" Idle cleanup of worker, "." Open slot with no current processSrv    PID    Acc    M    CPU    SS    Req    Dur    Conn    Child    Slot    Client    Protocol    VHost    Request1-0    9    0/1/1    _    0.00    50    3    3    0.0    0.05    0.05    172.29.0.1    http/1.1    172.29.0.2:80    GET /server-info HTTP/1.12-0    10    0/1/1    _    0.00    4    0    0    0.0    0.00    0.00    172.29.0.1    http/1.1    172.29.0.2:80    GET /serve-status HTTP/1.12-0    10    2/0/0    W    0.00    0    0    0    0.0    0.00    0.00    172.29.0.1    http/1.1    172.29.0.2:80    GET /server-status HTTP/1.1

拜访http://127.0.0.1/server-info获取服务根底配置信息

Apache Server InformationSubpages:Configuration Files, Server Settings, Module List, Active Hooks, Available ProvidersSections:Loaded Modules, Server Settings, Startup Hooks, Request Hooks, Other Hooks, ProvidersLoaded Modulescore.c, event.c, http_core.c, mod_access_compat.c, mod_alias.c, mod_auth_basic.c, mod_authn_core.c, mod_authn_file.c, mod_authz_core.c, mod_authz_groupfile.c, mod_authz_host.c, mod_authz_user.c, mod_autoindex.c, mod_dir.c, mod_env.c, mod_filter.c, mod_headers.c, mod_info.c, mod_log_config.c, mod_mime.c, mod_reqtimeout.c, mod_setenvif.c, mod_so.c, mod_status.c, mod_unixd.c, mod_version.c,Server SettingsServer Version: Apache/2.4.55 (Unix)Server Built: Feb 11 2023 09:43:46Server loaded APR Version: 1.7.2Compiled with APR Version: 1.7.2Server loaded APU Version: 1.6.3Compiled with APU Version: 1.6.3Server loaded PCRE Version: 8.45 2021-06-15Compiled with PCRE Version: 8.45 2021-06-15Module Magic Number: 20120211:126Hostname/port: 127.0.0.1:80Timeouts: connection: 60    keep-alive: 5MPM Name: eventMPM Information: Max Daemons: 4 Threaded: yes Forked: yesServer Architecture: 64-bitServer Root: /usr/local/apache2Config File: /usr/local/apache2/conf/httpd.confServer Built With:  -D APR_HAS_SENDFILE -D APR_HAS_MMAP -D APR_HAVE_IPV6 (IPv4-mapped addresses enabled) -D APR_USE_PROC_PTHREAD_SERIALIZE -D SINGLE_LISTEN_UNSERIALIZED_ACCEPT -D APR_HAS_OTHER_CHILD -D AP_HAVE_RELIABLE_PIPED_LOGS -D HTTPD_ROOT="/usr/local/apache2" -D SUEXEC_BIN="/usr/local/apache2/bin/suexec" -D DEFAULT_PIDLOG="logs/httpd.pid" -D DEFAULT_SCOREBOARD="logs/apache_runtime_status" -D DEFAULT_ERRORLOG="logs/error_log" -D AP_TYPES_CONFIG_FILE="conf/mime.types" -D SERVER_CONFIG_FILE="conf/httpd.conf"Startup Hooks