• TLS/SSL Certificate Brands
    • RapidSSL - simple site security for less. It provides basic level customer confidence with the https, closed padlock and a static trust mark.
    • A range of digital certificate and trust products enable organizations of all sizes to maximize the security of their digital transactions cost-effectively.
    • The ideal solution for enterprises and large organizations. The Internet most recognized and trusted SSL brand.
    • A quick, cost-efficient, and effective solution to build secure connection. PositiveSSL certificates show your customers you’re employing serious security measures to keep their transactions and data safe.
    • SECTIGO, formerly COMODO CA, Creating trust online for individuals, e-merchants, enterprise, with its robust SSL security.
    • i
      How organizations best manage their certificate lifecycle?


      Download E-book
  • Certificate Products
    • Single Domain SSL
      One for main domain with free 'www' coverage.
    • Wildcard SSL
      Protect unlimited sub domains under main website.
    • Multi-Domain SSL
      One certificate for multiple domain names.
    • Domain Validation SSL
      It is quick and cost-efficient, really. Basic protection.
    • Organization Validation SSL
      It gives your website an online idenity. For SMBs to strengthen web trust.
    • Extended Validation SSL
      Stand out your buiness entity, protect brand and transactions.
    • Email (Client) Certificate
      Encrypt and signed email, enable two-factor authentication, and implement strong digital trust practices throughout your organization.
    • Code Signing Certificate
      Boost Software Adoption and improve customer's trust with Code Signing. Digitally sign Code across popular platforms.
  • Domain & Email
    • Domain Name Registration
      Get your perfect domain name
    • Domain Reseller
      Reseller Pricing & TLDs
    • Transfer Domain
      Transfer domain into BestCert
    • Business Email
      Business Email builds customer trust
  • Site Builder
  • PKI Solutions
  • Partner
  • About Us
Nginx 和 PHP之间是如何协同工作的?


本文档介绍了Nginx和PHP-FPM之间的协同工作方式。当在Nginx上使用PHP时,Nginx主要负责处理客户端请求并将其转发到PHP-FPM进程池中的合适进程进行处理。PHP-FPM支持FastCGI协议,该协议可与Nginx一起用于处理来自客户端的HTTP请求。文章还提供了一个简单示例,帮助您配置 Nginx 和 PHP-FPM以展示如何实现。


当在 Nginx 上使用 PHP 时,Nginx 主要负责处理客户端请求并将其转发到 PHP-FPM 进程池中的合适进程进行处理。PHP-FPM 支持 FastCGI 协议,该协议可与 Nginx 一起用于处理来自客户端的 HTTP 请求。

以下是 Nginx 和 PHP-FPM 之间的工作流程:

1. 客户端发送 HTTP 请求到 Nginx 服务器。

2. Nginx 监听到请求后,开始检查配置文件以确定如何处理请求。

3. 如果 Nginx 配置文件中包含php-fpm相关配置,它将启动一个 FastCGI 请求将请求传递给 PHP-FPM 进程池。

4. PHP-FPM 从进程池中选择一个可用的进程来处理该请求。如果没有可用的进程,则 PHP-FPM 将启动一个新进程来处理该请求。

5. 选定的 PHP-FPM 进程获取该请求并将其解码,然后开始执行 PHP 代码。

6. 执行 PHP 代码后,PHP-FPM 将响应返回给 Nginx。

7. Nginx 接收到响应后,将其返回给客户端。

这种方式在高流量网站上非常有用,因为它能够显著减少服务器负载,使服务器更能够有效地处理大量并发请求。此外,它还可以提高网站的性能和稳定性。


简单示例Nginx和PHP-FPM的配置

1. 安装必要软件


sudo apt-get update

sudo apt-get install nginx php-fpm


2. 配置 Nginx

在Nginx的配置文件中,使用location指令定义处理 PHP 脚本请求的位置。以下是一个简单的示例:


server {

   listen 80;
   server_name example.com;

   root /var/www/example.com;
   index index.php;

   location ~ \.php$ {
       include fastcgi_params;
       fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
       fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
       fastcgi_param QUERY_STRING $query_string;
   }
}


3. 配置 PHP-FPM

PHP-FPM 的默认配置通常已经能够很好地处理大部分情况,但也可以根据需要进行调整。

在 Debian / Ubuntu 系统上,PHP-FPM 配置文件位于 /etc/php/7.0/fpm/pool.d/www.conf,您可以使用默认值开始,然后根据需要进行调整。

4. 重启服务并测试

完成配置之后,重新启动 Nginx 和 PHP-FPM:


sudo systemctl restart nginx

sudo systemctl restart php7.0-fpm


可以测试是否已正确配置 PHP 运行时。在 /var/www/example.com 中创建一个名为 test.php 的文件,其中包含以下内容:



<?php phpinfo(); ?>


在浏览器中输入该网站的url,然后导航到 /test.php。如果正常工作,则应该看到 PHP 信息页面。

这就是 Nginx 和 PHP-FPM 协同工作的基本知识。


厦门聚力诚信科技有限公司(BestCert.net)是网络安全领域的专业服务提供商,提供具备国际和国密双算法认证的数字证书管理服务,涵盖所有市场主流的SSL证书类型和品牌。公司致力于保护客户的网站等数字资产不受黑客和其他网络的侵害。此外,公司还为各行业客户提供电子签章、身份认证等电子认证服务解决方案来确保客户的数字身份安全。作为专业的网络安全服务提供商,公司注重确保客户数字资产的保密性、完整性和可用性,为客户提供全程在线支持,帮助客户应对安全问题和风险。





Chat Now

Email Us

Email Address:

sales@bestcert.net

Top