您的位置:首页技术文章
文章详情页

index of显示apache和php版本信息

【字号: 日期:2024-06-30 17:22:53浏览:86作者:猪猪

问题描述

index of显示apache和php版本信息

大神们,在图中红框这个地方把apache和php版本信息显示出来,apache是哪个配置项

问题解答

回答1:

你所看到的这个文件目录直接显示的页面,是Apache的 mod_autoindex 模块负责处理的。

先说说之前别人提到的那个ServerSignature 和 ServerTokens

ServerTokens FullServerSignature 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 ProdServerSignature 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 .phpAddType text/html .phpReadmeName /README.php HeaderName HEADER.html

ReadmeName 和 HeaderName 可能已经存在,那就改掉。

然后在你网站的根目录(your.domain.com/ 对应的那个目录)建立README.php

内容:

<?phpecho 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显示出来的信息都长啥样

回答2:

这个主要涉及两个配置 ServerSignature 和 ServerTokens , ServerSignature 起开关作用,ServerTokens 控制显示信息多少。修改 httpd.conf 这两个配置为以下,然后重启就可以显示。

ServerSignature OnServerTokens Full

附两个配置的相关值

ServerSignature : Off | On | Email

ServerTokens : Prod | Major | Minor | Min | OS | Full (显示内容从小到多)

相关文章: