加載 mod_autoindex 模塊
Apache 2.4版本,如果要控制站點(diǎn)目錄是否顯示,需要 mod_autoindex 模塊。如果沒有該模塊,顯示站點(diǎn)目錄的指令無效。
加載該模塊
LoadModule autoindex_module modules/mod_autoindex.so
方法一
解決過程:首先查看apache官網(wǎng)文檔,不能快速找到需要的部分。用搜索引擎查找“apache顯示站點(diǎn)目錄”,找到相關(guān)資料,雷同。按照資料說明配置無效。
開始嘗試在虛擬主機(jī)和非虛擬主機(jī)嘗試資料中的配置,仍然無效。再回到官網(wǎng)文檔查找關(guān)鍵詞“Options Indexes”,看到“mod_autoindex can generate a listing of the directory contents”,
然后全文檢索httpd.conf,意識(shí)到是因?yàn)橄嚓P(guān)模塊沒有加載。
虛擬主機(jī)顯示站點(diǎn)目錄
apache 2.4版本默認(rèn)不顯示站點(diǎn)目錄,虛擬主機(jī)配置如下:
1
2
3
4
5
6
7
|
<VirtualHost *:80> ServerAdmin [email protected] DocumentRoot "E:\wamp64\www\my-site\test-php" ServerName test -php.com ErrorLog "logs/test-php.com-error.log" CustomLog "logs/test-php.com-access.log" common < /VirtualHost > |
加入顯示站點(diǎn)目錄的指令 Options +Indexes,完整代碼如下:
1
2
3
4
5
6
7
8
9
10
|
<VirtualHost *:80> <Directory "E:\wamp64\www\my-site\test-php" > Options +Indexes # 顯示站點(diǎn)目錄 < /Directory > ServerAdmin [email protected] DocumentRoot "E:\wamp64\www\my-site\test-php" ServerName test -php.com ErrorLog "logs/test-php.com-error.log" CustomLog "logs/test-php.com-access.log" common < /VirtualHost > |
Options +Indexes 或 Options Indexes 或沒有這條指令,顯示站點(diǎn)目錄。
Options -Indexes,禁止顯示站點(diǎn)目錄。
以上所述是小編給大家介紹的Apache控制是否顯示站點(diǎn)目錄,希望對(duì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)服務(wù)器之家網(wǎng)站的支持!