Apache禁止显示目录结构

存在的问题:

缺省情况下如果你在浏览器输入地址:http://www.example.com

如果你的文件根目录里有 index.html,浏览器就会显示 index.html的内容,如果没有 index.html,浏览器就会显示文件根目录的目录列表,目录列表包括文件根目录下的文件和子目录。

解决办法:

第一种情况,如果有开启虚拟主机配置

虚拟主机配置文件修改,打开httpd-vhosts.conf文件

# Virtual Hosts
#
<VirtualHost *:80>
	ServerName www.example.com
	DocumentRoot E:/website
	<Directory  "E:/website">
		Options +Indexes +Includes +FollowSymLinks +MultiViews
		AllowOverride All
		Require all granted
	</Directory>
</VirtualHost>

删除Optinons项中的 "+Indexes"

# Virtual Hosts
#
<VirtualHost *:80>
	ServerName www.example.com
	DocumentRoot E:/website
	<Directory  "E:/website">
		Options  +Includes +FollowSymLinks +MultiViews
		AllowOverride All
		Require all granted
	</Directory>
</VirtualHost>

修改https配置文件,打开httpd-ssl.conf文件

Listen 443
<VirtualHost *:443>
        SSLEngine on
        SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP
        SSLCertificateFile "C:/wamp64/bin/apache/apache2.4.23/conf/cert/www.example.com_public.crt"
		SSLCertificateKeyFile "C:/wamp64/bin/apache/apache2.4.23/conf/cert/www.example.com.key"
		SSLCertificateChainFile "C:/wamp64/bin/apache/apache2.4.23/conf/cert/www.example.com_chain.crt"
        ServerName      "www.example.com"
        DocumentRoot    "E:/website"
	<Directory />
		AllowOverride All
		Order allow,deny
		Allow from all
		Options Indexes FollowSymLinks
	</Directory>
	SSLProxyEngine on
	ProxyRequests Off
	ProxyPass /wss ws://127.0.0.1:8888
	ProxyPassReverse /wss ws://127.0.0.1:8888
</VirtualHost>
SSLProtocol all -SSLv2 -SSLv3
SSLCipherSuite HIGH:!RC4:!MD5:!aNULL:!eNULL:!NULL:!DH:!EDH:!EXP:+MEDIUM
SSLHonorCipherOrder on

同样删除Options 中的 "Indexes"

Listen 443
<VirtualHost *:443>
        SSLEngine on
        SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP
        SSLCertificateFile "C:/wamp64/bin/apache/apache2.4.23/conf/cert/www.example.com_public.crt"
		SSLCertificateKeyFile "C:/wamp64/bin/apache/apache2.4.23/conf/cert/www.example.com.key"
		SSLCertificateChainFile "C:/wamp64/bin/apache/apache2.4.23/conf/cert/www.example.com_chain.crt"
        ServerName      "www.example.com"
        DocumentRoot    "E:/website"
	<Directory />
		AllowOverride All
		Order allow,deny
		Allow from all
		Options Indexes FollowSymLinks
	</Directory>
	SSLProxyEngine on
	ProxyRequests Off
	ProxyPass /wss ws://127.0.0.1:8888
	ProxyPassReverse /wss ws://127.0.0.1:8888
</VirtualHost>
SSLProtocol all -SSLv2 -SSLv3
SSLCipherSuite HIGH:!RC4:!MD5:!aNULL:!eNULL:!NULL:!DH:!EDH:!EXP:+MEDIUM
SSLHonorCipherOrder on

第二种情况,没有配置虚拟主机的情况下,修改httpd.conf


DocumentRoot "D:/website"

<Directory "D:/website/">
	Options Indexes FollowSymLinks
	AllowOverride All
</Directory>

删除Optins项中的"Indexes"

posted @ 2022-07-25 16:20  panbin_2006  阅读(118)  评论(0编辑  收藏  举报