AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 996948
Accepted
NickSoft
NickSoft
Asked: 2019-12-29 02:02:26 +0800 CST2019-12-29 02:02:26 +0800 CST 2019-12-29 02:02:26 +0800 CST

Apache 目录索引在子目录中不起作用

  • 772

我有一个简单的文件服务器(centos 7 上的 apache 2.4),其结构如下: /index.html - 一个确保此处没有目录列表的页面 /upload - 用于上传的 php 脚本 /storage - 文件的基本目录 /storage/ upload - 由 php 上传的文件 /storage/public - 不受密码保护的文件

我无法使目录列表工作。例如在 /storage/public 我看到 /index.html 页面。/storage/public 中没有 index.html。如果我删除此页面,我会在 /page 中看到默认的 apache“testing 123”页面,并且目录列表在 /storage/public(以及所有其他具有 +Indexes 的地方)中有效。为什么 /index.html 显示在 /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>

更新:

# apachectl -M|grep autoindex
 autoindex_module (shared)

另一个虚拟主机有以下问题:我使用的虚拟主机的根文件夹中有 index.html

Options -ExecCGI -Indexes

所以我有一个子目录 /test 并放了另一个 index.html,但是当我在浏览器中打开 /test/ 时,我看到 /index.html 而不是 /test/index.html

这个虚拟主机中根本没有 php。

linux
  • 3 3 个回答
  • 3641 Views

3 个回答

  • Voted
  1. hargut
    2020-01-04T01:12:05+08:002020-01-04T01:12:05+08:00

    列出的问题给人的印象是所涉及的文件夹中的权限存在问题。

    有几种权限需要检查:

    • 处理 httpd 的用户/组:

      • 利用ps axo pid,user,group,comm
    • 文件系统权限:

      • 用户、组、读、写、执行标志(使用ls -l和或ls -lR,ls -ld)
    • SELinux 权限:

      • 如果它处于活动状态,这可能在 CentOS 上(用于sestatus验证状态和模式)
      • 文件权限上下文(使用ls -lZand or ls -lRZ ls -ldZ)
      • httpd SELinux 上下文(使用ps -axZ | grep httpd)
      • SELinux 布尔值(使用getsebool -a | grep httpd)
      • 在尝试生成目录列表时检查审计日志(使用tail -f /var/log/audit/audit.log)
    • 1
  2. Best Answer
    NickSoft
    2020-01-06T08:53:25+08:002020-01-06T08:53:25+08:00

    问题是我更改了全局设置:

    DirectoryIndex index.php index.html
    

    至:

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

    为了解决另一个问题- 我使用带有 ProxyPassMatch 指令的 php fpm 服务器,如下所示:

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

    正如我在 apache.org 上阅读的那样。使用 ProxyPassMatch 和 index.php 时的问题是缺少 apache 不加载 index.html(另一个类似的问题)

    将全局指令恢复为:

    DirectoryIndex index.php index.html
    

    解决了这个问题,但是当缺少 index.php 时,当 vhost apache 中的 ProxyPassMatch 没有回退到 index.html 时,我仍然遇到问题。

    现在我必须将赏金奖励给某人。如果我不能在两个答案之间拆分它,我会将它授予 little_dog,因为我认为他更接近我的问题。

    • 1
  3. little_dog
    2019-12-30T15:39:08+08:002019-12-30T15:39:08+08:00

    检查您是否已启用自动索引模块,按:apachectl -M应该是:

    Loaded Modules:
    ...
    autoindex_module (shared)
    ...
    

    如果不是,您需要启用它,在 Centos 中参考:https ://unix.stackexchange.com/questions/258854/disable-and-enable-modules-in-apache-centos7

    更新#1

    对于目录列表工作,您的目录中不能有 index.html,请检查: https ://cwiki.apache.org/confluence/display/httpd/DirectoryListings

    如果 DirectoryIndex 指令中的文件不能位于目录中,则 mod_autoindex 可以生成目录内容列表。

    • 0

相关问题

  • Linux 主机到主机迁移

  • 如何在 Linux 机器上找到有关硬件的详细信息?

  • 如何在 Linux 下监控每个进程的网络 I/O 使用情况?

  • 在 RHEL4 上修改 CUPS 中的现有打印机设置

  • 为本地网络中的名称解析添加自定义 dns 条目

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve