大网数据广告活动
服务器运维问答

Apache Directory indexing does not work in a subdirectory

· 52CE 我爱测

I have a simple file server (apache 2.4 on centos 7) with following structure: /index.html - a page to make sure there is no directory listing here /upload - php scripts for upload /storage - base dir for files /storage/upload - …

问题原文

原帖链接 · NickSoft · CC BY-SA 4.0

I have a simple file server (apache 2.4 on centos 7) with following structure: /index.html - a page to make sure there is no directory listing here /upload - php scripts for upload /storage - base dir for files /storage/upload - files uploaded by php /storage/public - files that are not password protected

I can't make directory listing work. For example in /storage/public I see the /index.html page. There is no index.html in /storage/public. If I delete this page I see default apache "testing 123" page in / page and directory listing works in /storage/public (and all other places that have +Indexes). Why /index.html is showing in /storage/public/

<IfModule mod_ssl.c>
<VirtualHost *:443>
  DocumentRoot "/home/webroot/www"
  ServerName subdomain.example.com

  ErrorLog "/home/rootdir/log/subdomain.error.log"
  CustomLog "/home/rootdir/log/subdomain.access.log" common

  SuexecUserGroup user apache

#Set caching on image files for 11 months
<filesMatch "\.(ico|gif|jpg|png|js|css)$">
  #ExpiresActive On
  #ExpiresDefault "access plus 11 month"
  Header append Cache-Control "public"
</filesMatch>

  <Directory "/home/webroot/www" >
    AllowOverride None
    Options -ExecCGI -Indexes +Includes +SymLinksIfOwnerMatch +MultiViews

    Require all granted
  </Directory>
  <Directory "/home/webroot/www/storage/upload" >
    AllowOverride None
    AuthType Basic
    AuthName "Restricted Content"
    AuthUserFile /home/rootdir/.htpasswd
    Require valid-user
    <FilesMatch "\.php$">
      SetHandler "proxy:unix:/usr/local/php73/var/run/php-fpm.sock|fcgi://localhost/"
    </FilesMatch>

  </Directory>
  <Directory "/home/webroot/www/storage/" >
    AllowOverride None
    Options +Indexes +SymLinksIfOwnerMatch +MultiViews

    AuthType Basic
    AuthName "Restricted Content"
    AuthUserFile /home/rootdir/.htpasswd
    Require valid-user
    #Require all granted
    RemoveType .php

    Order allow,deny
    Allow from all
  </Directory>

  <Directory "/home/webroot/www/storage/public" >
    Options +Indexes +SymLinksIfOwnerMatch +MultiViews
    AuthType None
    Require all granted
    Satisfy Any
  </Directory>

  <Directory "/home/webroot/www/.well-known" >
    AuthType None
    Require all granted
    Satisfy Any
    Allow from all
  </Directory>

  <Directory "/home/webroot/www/storage/upload" >
    AuthType Basic
    AuthName "Restricted Content"
    AuthUserFile /home/rootdir/.htpasswd
    Require valid-user
  </Directory>

  <IfModule mod_deflate.c>
    AddOutputFilterByType DEFLATE text/text text/html text/plain text/xml text/css text/javascript application/x-javascript application/javascript
  </IfModule>


Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/subdomain.example.com/cert.pem
SSLCertificateKeyFile /etc/letsencrypt/live/subdomain.example.com/privkey.pem
SSLCertificateChainFile /etc/letsencrypt/live/subdomain.example.com/chain.pem

</VirtualHost>
</IfModule>

Update:

# apachectl -M|grep autoindex
 autoindex_module (shared)

Another vhost have the following problem: there is index.html in root folder for the vhost I use

Options -ExecCGI -Indexes

So I have a subdirectory /test and I put another index.html, but when I open /test/ in my browser I see the /index.html instead of /test/index.html

No php in this vhost at all.

已采纳解答

原帖链接 · NickSoft · CC BY-SA 4.0

The problem was that I had changed the global setting from:

DirectoryIndex index.php index.html

to:

DirectoryIndex /index.php index.php /index.html index.html

in an effort to fix another problem - I use php fpm server with ProxyPassMatch directive like this:

ProxyPassMatch ^/(.*.php(/.*)?)$ unix:/path/to/php-fpm.sock|fcgi://localhost/home/userdir/www/$1

As I read on apache.org. The problem with that when using ProxyPassMatch and index.php is missing apache does not load index.html (another similar problem)

Restoring global directive to:

DirectoryIndex index.php index.html

fixed the problem, but I still have the problem when having ProxyPassMatch in the vhost apache does not fall back to index.html when index.php is missing.

Now I have to award the bounty to someone. If I can't split it between the two answers I'll award it to little_dog because I think he's a bit closer to my issue.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2019-12-28)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。