为什么 php-fpm 监听端口 9000?

发布于 2025-01-13 07:49:10 字数 455 浏览 6 评论 0原文

➜  ~ sudo lsof -i :9000

COMMAND   PID USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
php-fpm 23153 root    8u  IPv4 0xbdb928c0ec095c13      0t0  TCP localhost:cslistener (LISTEN)
php-fpm 23154 _www    9u  IPv4 0xbdb928c0ec095c13      0t0  TCP localhost:cslistener (LISTEN)
php-fpm 23155 _www    9u  IPv4 0xbdb928c0ec095c13      0t0  TCP localhost:cslistener (LISTEN)

当然,我的 Mac 上安装了 PHP。但为什么它总是在 9000 上收听?这是否存在安全风险?

➜  ~ sudo lsof -i :9000

COMMAND   PID USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
php-fpm 23153 root    8u  IPv4 0xbdb928c0ec095c13      0t0  TCP localhost:cslistener (LISTEN)
php-fpm 23154 _www    9u  IPv4 0xbdb928c0ec095c13      0t0  TCP localhost:cslistener (LISTEN)
php-fpm 23155 _www    9u  IPv4 0xbdb928c0ec095c13      0t0  TCP localhost:cslistener (LISTEN)

sure, I have PHP installed on my mac. But why is it listening on 9000 always? is it a security risk?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

守不住的情 2025-01-20 07:49:10

当 PHP 最初发布时,PHP 主要作为 Apache Web 服务器的插件运行,名为 mod-php

基本上,当加载 mod_php 作为 Apache 模块时,它允许 Apache 解释 PHP 文件

这是运行 PHP 的“快速且简单”的方式。您只需配置 Apache 即可加载 PHP 模块,它是所谓的 LAMP 堆栈。但这也意味着 PHP 受到 Apache 的限制,这可能会影响性能。随着性能变得越来越重要,并且随着 nginx 等其他 Web 服务器的兴起,有必要让 PHP 在自己的进程下运行,这意味着您可以独立于 Web 服务器来调整 PHP。

PHP-FPM 是一项接受处理 PHP 文件请求的服务。它并不关心您正在运行什么 Web 服务器,并且默认情况下,它接受端口 9000 上的 Web 服务器连接。 来自 nginx 默认配置

fastcgi_pass 127.0.0.1:9000;

另一种默认方式是通过 Linux 套接字文件。 Ubuntu 下 Apache2 是这样做的

<FilesMatch ".+\.ph(ar|p|tml)$">
    SetHandler "proxy:unix:/run/php/php7.4-fpm.sock|fcgi://localhost"
</FilesMatch>

有安全风险吗?

不可以。在侦听套接字时,您的服务器不应配置为侦听端口 9000 上的公共流量。这就是您的网络服务器正在做的事情。只有服务器本地的东西才应该访问端口 9000。

When PHP was originally put out there, PHP mostly ran as a plugin of the Apache web server called mod-php

Basically, when loading mod_php as an Apache module, it allows Apache to interpret PHP files

This was the "quick and easy" way to run PHP. You only had to have Apache configured to load the PHP module, and it was a cornerstone of the so-called LAMP stack. But it also meant that PHP was constrained by Apache, which could hamper performance. As performance became more of an issue, and with the rise of other web servers like nginx, there was a need for PHP to run under its own processes, which meant you could tune PHP separately from the web server.

PHP-FPM is a service that accepts requests to process PHP files. It doesn't care what web server you're running and, by default, it accepts those web server connections on port 9000. From the nginx default configuration

fastcgi_pass 127.0.0.1:9000;

The other default way is over a Linux socket file. Here's how Apache2 does it under Ubuntu

<FilesMatch ".+\.ph(ar|p|tml)
quot;>
    SetHandler "proxy:unix:/run/php/php7.4-fpm.sock|fcgi://localhost"
</FilesMatch>

Is it a security risk?

No. While it's listening on a socket, your server should not be configured to listen on port 9000 for public traffic. That's what your web server is doing. Only things local to your server should be accessing port 9000.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文