PHP 默认设置安装的 Web 服务器存在信息泄露风险,服务器中隐藏 PHP 版本信息可以提高安全性。本文对此进行简要说明。
1. 默认 expose_php 默认是开的。如下图所示:
2. 关闭 expose_php 参数可以隐藏 php 版本信息。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | <ol class = "linenums" > <li class = "L0" ><span class = "pln" >$ vi </span><span class = "pun" >/</span><span class = "pln" >etc</span><span class = "pun" >/</span><span class = "pln" >php</span><span class = "pun" >.</span><span class = "pln" >ini </span></li> <li class = "L1" ><span class = "com" >#每个的用户配置可能不一样,可以通过如下指令查找文件路径:</span></li> <li class = "L2" ></li> <li class = "L3" ><span class = "pln" >find </span><span class = "pun" >/</span><span class = "pln" > </span><span class = "pun" >-</span><span class = "pln" >name php</span><span class = "pun" >.</span><span class = "pln" >ini </span></li> <li class = "L4" ></li> <li class = "L5" ><span class = "com" ># 在 php.ini, 定位到含有 expose_php 的那行把 On 设成 Off</span></li> <li class = "L6" ><span class = "pln" >expose_php </span><span class = "pun" >=</span><span class = "pln" > </span><span class = "typ" >Off</span></li> </ol> |
3. 更改并重启 Web 服务后,PHP 就不会在 Web 服务头中显示版本了: