How does nginx interact with PHP?

There are several common ways to interact between nginx and php.

  1. “Using FastCGI, nginx acts as a reverse proxy server to forward requests to PHP-FPM for processing. PHP-FPM communicates with nginx via the FastCGI protocol and returns the processing results to nginx, which then delivers the results to the client.”
  2. Nginx directly forwards requests to PHP-FPM, which acts as an independent PHP process manager responsible for communicating with Nginx and executing PHP scripts.
  3. nginx is able to redirect requests to a PHP interpreter such as php-cgi, which then interprets and executes the PHP script before sending the results back to nginx.
  4. WebSocket: nginx can act as a WebSocket server to enable bidirectional communication with PHP, allowing for real-time bidirectional communication.

Each method has its own advantages and disadvantages, so choose the appropriate way to interact between nginx and PHP based on specific scenarios and needs.

bannerAds