You can improve the work of the web server which hosts customer websites by installing nginx, a supplementary high-performance web server which is typically used as a reverse proxy server. This web server was specifically designed for delivering large amounts of static content (like images, video, css, xml, and so on). As opposed to Apache, nginx is much more efficient when it comes to a large number of concurrent connections. Another advantage of this web server comparing with Apache is that nginx has significantly lower memory footprint per client connection.
To leverage all benefits of nginx, Panel configures it as a reverse proxy server that stands between the Internet and Apache (see the diagram below). This means that nginx becomes a frontend web server that processes all incoming requests from site visitors. The requests are sent to Apache which, in turn, distinguishes requests for static and dynamic content. If a request is for a static file (like jpg, css, html, and so on), Apache passes the request through all registered handlers (applies
.htaccess directory-level configuration, rewrites a URL, and so on) and returns to nginx a response which contains only a location of the requested file on the file system. nginx locates the file and sends it to the client. If the request is for a dynamic file (like a PHP script), Apache executes the file and sends the response to nginx, which delivers it to the client.
Such combination of nginx and Apache gives the following advantages:
The technical details on how Panel processes HTTP requests with the help of nginx are provided next in this section. For the information on how to turn on the support for nginx in Panel, refer to the section Installing nginx. If you do not want to use nginx, make Apache your frontend web server following the instructions from the section Making Apache a Frontend Web Server.
How Panel with nginx Processes HTTP Requests
To seamlessly integrate nginx with Apache, Panel uses two additional Apache modules:
.htaccessrelated modules, mod_php, and so on). Therefore, if the request is for dynamic content, mod_aclr2 will never get it as the request will be served by upper-level handlers of certain Apache modules (mod_php, mod_perl, mod_cgi, and so on). The only exceptions are SSI requests: Once they reach mod_aclr2, it redirects them to proper handlers. If the request is for a static file, mod_aclr2 searches for the exact file location on the file system and sends the location to nginx.
Let us take a closer look on how Panel processes requests for static and dynamic content with the help of these modules.
The sequence of processing an HTTP request for a static file is as follows (see the diagram for the convenience):
.htaccessconfiguration, rewrites URL, and so on). At this step, mod_rpaf replaces the IP address of the nginx server in the REMOTE_ADDR Apache variable with the client's address from the X-Forwarded-For header.
The diagram below is the example of how Panel handles the request for the 2 KB GIF file.
In case of processing requests for dynamic content, the steps from 1 to 3 are the same. Then the request passes to the handler of the appropriate Apache module (mod_php, mod_perl, mod_cgi, and so on): The request never reaches mod_aclr2 (excepting SSI requests). The handler generates a response and sends it to nginx, which, in turn, delivers the response to the client. The diagram below illustrates how Panel processes a request for some PHP file.
If you perform a clean installation of Panel 11, nginx will be turned on by default. If you upgrade from earlier versions, you can add the nginx component at any time after the upgrade in Tools & Settings > Updates & Upgrades > Add Components. Once the component is added, you should run the Reverse Proxy Server (nginx) service in Tools & Settings > Services Management.
You can view the version of the installed nginx server in Tools & Settings > Server Components.
To return back to the configuration with a single Apache web server, stop the Reverse Proxy Server (nginx) service in Tools & Settings > Services Management.
Once you run the service, nginx will become a frontend web server again.
Note: The start and stop operations for the Reverse Proxy Server (nginx) service not only start and stop nginx, they actually switch web server configuration (nginx and Apache combination or just Apache as a frontend web server). The restart operation works in the same way as for all other services: The nginx service is restarted.