3

PHP 服务挂了之后是不是就能查看. PHP 文件源码了?

 2 years ago
source link: https://www.v2ex.com/t/809602
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

V2EX  ›  PHP

PHP 服务挂了之后是不是就能查看. PHP 文件源码了?

  ysy950803 · 2 小时 21 分钟前 · 379 次点击

问个小白问题,有这么一个场景,假如我把.php 文件放在网站目录下,和 index.html 同目录,可通过浏览器访问的那种。 比如有一个 test.php 文件,里面有一些 PHP 代码,不渲染任何东西,当服务正常的时候,浏览器显示空白,这是正常情况。但如果 fpm 等相关服务挂掉了,是不是再访问就直接视为普通文本文件返回给浏览器了?这样就能看见源码了?

8 条回复    2021-10-21 19:31:24 +08:00

xmlf

xmlf   2 小时 19 分钟前 via Android

你可以自己测试一下。

AoEiuV020

AoEiuV020   2 小时 19 分钟前

一般是 502,nginx 返回的,

ysy950803

ysy950803   2 小时 18 分钟前

@AoEiuV020 不是 Nginx 呢,是 Apache 。

ysy950803

ysy950803   2 小时 17 分钟前

@xmlf 哈哈哈害怕关了不会起了,不太熟,对 PHP 服务。

InDom

InDom   2 小时 15 分钟前

有可能会,但绝大多数配置正确的情况下并不会。

以 Nginx 来举例,如果你把 .php 配置到了 php-fpm 后,如果 fpm 挂了,它会尝试连接 fpm 失败后直接报错。

而不是把 php 文件作为文本来输出,如果你 .php 文件没有在 Nginx 内正确处理,就算 fpm 没挂也会作为文本输出。

综上,在 Nginx 作为 WebServer 的情况下,是否可能输出 php 文件源代码和 fpm 挂没挂基本没有直接关系,只和 Nginx 本身的配置是否有关。

ysy950803

ysy950803   2 小时 12 分钟前

@InDom 感谢解答。那这么说.php 文件放在网站目录还是有一定的安全风险。

demoshengxw

demoshengxw   1 小时 9 分钟前 via Android

并不能,因为 php 部署只会开放入口文件。而且 nginx 会转发给 fpm,fpm 挂了那 nginx 收不到正确响应,就会吐给浏览器 5xx 错误

hxy100

hxy100   1 小时 5 分钟前

并不会,了解下什么叫 MIME type,只要你 MIME type 配置正确(通常情况下以文件后缀名作为区分),无论服务怎么挂,是不会暴露源码的,除非你把.php 后缀的文件配置成 txt 形式( text/plain )加载,这样无论服务挂不挂都会暴露源码。

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK