autoindex_module이 php:apache에서 작동하지 않나요?
P粉764785924
2023-09-02 13:15:45
<p>我使用 Docker 创建了一个包含 php:apache 的容器。
我想使用该环境来运行各种 PHP 文件并尝试很多事情。</p>
<p>访问没有 index.* 的路径会因错误 403 而被拒绝。
如何激活自动索引并查看目录列表?</p>
<p>http://localhost:8000/ 返回此值。</p>
<pre class="brush:php;toolbar:false;">Forbidden
You don't have permission to access this resource.
Apache/2.4.56 (Debian) Server at localhost Port 8000</pre>
<p>容器日志是这样的。</p>
<pre class="brush:php;toolbar:false;">Attaching to name
name | AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.26.0.2. Set the 'ServerName' directive globally to suppress this message
name | AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.26.0.2. Set the 'ServerName' directive globally to suppress this message
name | [Sun May 28 06:45:53.417048 2023] [mpm_prefork:notice] [pid 1] AH00163: Apache/2.4.56 (Debian) PHP/8.2.6 configured -- resuming normal operations
name | [Sun May 28 06:45:53.417105 2023] [core:notice] [pid 1] AH00094: Command line: 'apache2 -D FOREGROUND'</pre>
<h2>源代码</h2>
<p>./docker-compose.yml</p>
<pre class="brush:php;toolbar:false;">version: '3.8'
services:
php:
container_name: name
image: php:apache
volumes:
- ./src:/var/www/html
- ./config/apache:/usr/local/apache2/conf
ports:
- 8000:80</pre>
<p>./config/apache/httpd.conf</p>
<pre class="brush:php;toolbar:false;">LoadModule autoindex_module modules/mod_autoindex.so</pre>
<p>./src/phpinfo.php</p>
<pre class="brush:php;toolbar:false;"><?php
phpinfo();</pre>
<p>http://localhost:8000/phpinfo.php 返回此值。</p>
<pre class="brush:php;toolbar:false;">PHP logo
PHP Version 8.2.6
System Linux b2abb5b31a3e 5.15.90.1-microsoft-standard-WSL2 #1 SMP Fri Jan 27 02:56:13 UTC 2023 x86_64
Build Date May 23 2023 09:41:46
Build System Linux d4bc11463019 5.10.0-13-cloud-amd64 #1 SMP Debian 5.10.106-1 (2022-03-17) x86_64 GNU/Linux
Configure Command './configure' '--build=x86_64-linux-gnu' '--with-config-file-path=/usr/local/etc/php' '--with-config-file-scan-dir=/usr/local/etc/php/conf.d' '--enable-option-checking=fatal' '--with-mhash' '--with-pic' '--enable-ftp' '--enable-mbstring' '--enable-mysqlnd' '--with-password-argon2' '--with-sodium=shared' '--with-pdo-sqlite=/usr' '--with-sqlite3=/usr' '--with-curl' '--with-iconv' '--with-openssl' '--with-readline' '--with-zlib' '--disable-phpdbg' '--with-pear' '--with-libdir=lib/x86_64-linux-gnu' '--disable-cgi' '--with-apxs2' 'build_alias=x86_64-linux-gnu'
Server API Apache 2.0 Handler
Virtual Directory Support disabled
Configuration File (php.ini) Path /usr/local/etc/php
Loaded Configuration File (none)
Scan this dir for additional .ini files /usr/local/etc/php/conf.d
Additional .ini files parsed /usr/local/etc/php/conf.d/docker-php-ext-sodium.ini
PHP API 20220829
PHP Extension 20220829
Zend Extension 420220829
Zend Extension Build API420220829,NTS
PHP Extension Build API20220829,NTS
Debug Build no
Thread Safety disabled
Zend Signal Handling enabled
Zend Memory Manager enabled
Zend Multibyte Support provided by mbstring
Zend Max Execution Timers disabled
IPv6 Support enabled
DTrace Support disabled
Registered PHP Streams https, ftps, compress.zlib, php, file, glob, data, http, ftp, phar
Registered Stream Socket Transports tcp, udp, unix, udg, ssl, tls, tlsv1.0, tlsv1.1, tlsv1.2, tlsv1.3
Registered Stream Filters zlib.*, convert.iconv.*, string.rot13, string.toupper, string.tolower, convert.*, consumed, dechunk
Zend logoThis program makes use of the Zend Scripting Language Engine:
Zend Engine v4.2.6, Copyright (c) Zend Technologies
Configuration
apache2handler
Apache Version Apache/2.4.56 (Debian)
Apache API Version 20120211
Server Administrator webmaster@localhost
Hostname:Port 172.24.0.3:80
User/Group www-data(33)/33
Max Requests Per Child: 0 - Keep Alive: on - Max Per Connection: 100
Timeouts Connection: 300 - Keep-Alive: 5
Virtual Server Yes
Server Root /etc/apache2
Loaded Modules core mod_so mod_watchdog http_core mod_log_config mod_logio mod_version mod_unixd mod_access_compat mod_alias mod_auth_basic mod_authn_core mod_authn_file mod_authz_core mod_authz_host mod_authz_user mod_autoindex mod_deflate mod_dir mod_env mod_filter mod_mime prefork mod_negotiation mod_php mod_reqtimeout mod_setenvif mod_status
Directive Local Value Master Value
engine On On
last_modified Off Off
xbithack Off Off
Apache Environment
Variable Value
HTTP_HOST localhost:8000
HTTP_CONNECTION keep-alive
HTTP_SEC_CH_UA "Google Chrome";v="113", "Chromium";v="113", "Not-A.Brand";v="24"
HTTP_SEC_CH_UA_MOBILE ?0
HTTP_SEC_CH_UA_PLATFORM "Windows"
HTTP_DNT 1
HTTP_UPGRADE_INSECURE_REQUESTS 1
HTTP_USER_AGENT Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36
HTTP_ACCEPT text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7
HTTP_SEC_FETCH_SITE none
HTTP_SEC_FETCH_MODE navigate
HTTP_SEC_FETCH_USER ?1
HTTP_SEC_FETCH_DEST document
HTTP_ACCEPT_ENCODING gzip, deflate, br
HTTP_ACCEPT_LANGUAGE ja,en;q=0.9
HTTP_COOKIE phpMyAdmin=4d288d3bece7895a9aad25518e619ca7; pma_lang=ja
PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
SERVER_SIGNATURE <address>Apache/2.4.56 (Debian) Server at localhost Port 8000</address>
SERVER_SOFTWARE Apache/2.4.56 (Debian)
SERVER_NAME localhost
SERVER_ADDR 172.24.0.3
SERVER_PORT 8000
REMOTE_ADDR 172.24.0.1
DOCUMENT_ROOT /var/www/html
REQUEST_SCHEME http
CONTEXT_PREFIX no value
CONTEXT_DOCUMENT_ROOT /var/www/html
SERVER_ADMIN webmaster@localhost
SCRIPT_FILENAME /var/www/html/phpinfo.php
REMOTE_PORT 52602
GATEWAY_INTERFACE CGI/1.1
SERVER_PROTOCOL HTTP/1.1
REQUEST_METHOD GET
QUERY_STRING no value
REQUEST_URI /phpinfo.php
SCRIPT_NAME /phpinfo.php
HTTP Headers Information
HTTP Request Headers
HTTP Request GET /phpinfo.php HTTP/1.1
Host localhost:8000
Connection keep-alive
sec-ch-ua "Google Chrome";v="113", "Chromium";v="113", "Not-A.Brand";v="24"
sec-ch-ua-mobile ?0
sec-ch-ua-platform "Windows"
DNT 1
Upgrade-Insecure-Requests 1
User-Agent Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36
Accept text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7
Sec-Fetch-Site none
Sec-Fetch-Mode navigate
Sec-Fetch-User ?1
Sec-Fetch-Dest document
Accept-Encoding gzip, deflate, br
Accept-Language ja,en;q=0.9
Cookie phpMyAdmin=4d288d3bece7895a9aad25518e619ca7; pma_lang=ja
HTTP Response Headers
X-Powered-By PHP/8.2.6</pre>
<h2>尝试</h2>
<p>我在 <code>name</code> 容器中运行这些命令。</p>
<pre class="brush:php;toolbar:false;"># ls -la /var/www/html
total 4
drwxrwxrwx 1 www-data www-data 512 May 28 06:17 .
drwxr-xr-x 1 root root 4096 May 23 09:36 ..
-rwxrwxrwx 1 www-data www-data 17 May 28 04:31 phpinfo.php
# apachectl -M
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.26.0.2. Set the 'ServerName' directive globally to suppress this message
Loaded Modules:
core_module (static)
so_module (static)
watchdog_module (static)
http_module (static)
log_config_module (static)
logio_module (static)
version_module (static)
unixd_module (static)
access_compat_module (shared)
alias_module (shared)
auth_basic_module (shared)
authn_core_module (shared)
authn_file_module (shared)
authz_core_module (shared)
authz_host_module (shared)
authz_user_module (shared)
autoindex_module (shared)
deflate_module (shared)
dir_module (shared)
env_module (shared)
filter_module (shared)
mime_module (shared)
mpm_prefork_module (shared)
negotiation_module (shared)
php_module (shared)
reqtimeout_module (shared)
setenvif_module (shared)
status_module (shared)</pre>
<p>./config/apache/httpd.conf</p>
<pre class="brush:php;toolbar:false;">LoadModule autoindex_module modules/mod_autoindex.so
<Directory "/var/www/html">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
DirectoryIndex index.php index.html
</Directory></pre>
<p>./docker-compose.yml</p>
<pre class="brush:php;toolbar:false;">command:
- apache2-foreground -D FOREGROUND
- a2enmod autoindex</pre>
<h2>环境</h2>
<ul>
<li>Windows 11 家庭版 22H2 22621.1778</li>
<li>Docker 4.19.0 (106363)</li>
</ul></p>
또한 인덱싱을 허용해야 합니다.
Options +Indexes
选项文档,当已有全局/默认配置时,您可能需要使用AllowOverride Options=Indexes
이 구성을 재정의합니다 apache.org/docs/current/mod/core.html#allowoverride" rel="nofollow noreferrer">AllowOverride 문서