index of显示apache和php版本信息
问题描述
大神们,在图中红框这个地方把apache和php版本信息显示出来,apache是哪个配置项
你所看到的这个文件目录直接显示的页面,是Apache的 mod_autoindex 模块负责处理的。
先说说之前别人提到的那个ServerSignature
和 ServerTokens
ServerTokens Full
ServerSignature On
mod_autoindex 的末尾信息:Apache/2.4.10 (系统 Debian/Ubuntu/Windows之类的) OpenSSL/1.0.1t Server at your.domain.com Port 443
Http头部:Server:Apache/2.4.10 (系统 Debian/Ubuntu/Windows之类的) OpenSSL/1.0.1t
ServerTokens Prod
ServerSignature Off
是这个样子的:
mod_autoindex 的末尾信息:Apache Server at your.domain.com Port 443
Http头部:Server:Apache
所以 ServerSignature
和 ServerTokens
和你的问题没什么直接关系。
也就是说,Apache没有什么配置项能直接解决这个问题(Apache又不是必须和PHP结合,安装了Apache人家凭什么给你顺便显示PHP的信息?)。
间接解决:我给的是Debian/Ubuntu系+mod_php的解决方案,别的系统估计也类似。
/etc/apache2/mods_enabled/autoindex.conf
</IfModule>
前面加上:
AddHandler application/x-httpd-php .php
AddType text/html .php
ReadmeName /README.php
HeaderName HEADER.html
ReadmeName
和 HeaderName
可能已经存在,那就改掉。
然后在你网站的根目录(your.domain.com/ 对应的那个目录)建立README.php
内容:
<?php
echo apache_get_version().', PHP Version:'.phpversion();
?>
注意啦,这里有个唯一可能跟 ServerTokens
有关的内容,如果你配置的是 Prod
, 则只能显示出来Apache
, 如果配置的是 Full
就会显示我之前提到的那一大串详细信息:
Apache/2.x.xx (系统 Debian/Ubuntu/Windows之类的) OpenSSL/1.0.xx
另外如果直接在php里调用shell_exec
获得Apache版本号的话应该没有限制,可以不动ServerTokens
配置。
更多参见:
Apache mod_autoindex 对于Header和Readme的详细说明
PHP 函数,获得Apache版本信息
PHP 获得PHP版本信息
要在调用这个PHP之前声明.php的Handler。尽管你在别处可能也有声明,但是这个配置文件被Apache处理的顺序比较靠前。所以要更提前的声明
不同的ServerTokens显示出来的信息都长啥样
这篇关于index of显示apache和php版本信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!