To seamlessly integrate nginx with Apache, Plesk uses two additional
Apache modules:
-
mod_aclr2
This module sets up a handler which runs after handlers of all other
Apache modules (mod_rewrite,.htaccess
related 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. -
mod_rpaf or mod_remoteip
From the point of view of Apache, all of its clients have the same IP
address - the address of the nginx server (see the diagram above).
This causes problems for websites and web apps that use client IP
addresses for authentication, statistic purposes, and so on. mod_rpaf
(in Apache 2.2) or mod_remoteip (in Apache 2.4) solves the problem by
replacing the IP address of the nginx server in all requests with
client IP addresses. In more detail, the module uses the special
X-Forwarded-For header in which nginx puts the IP address of a
client.
Let us take a closer look at how Plesk 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):
- A client sends a request to a web server.
- nginx adds the X-Accel-external (used by mod_aclr2) and
X-Forwarded-For (which contains the IP address of the client)
headers to the request and sends the request to Apache. - Apache receives the request and starts to process it by registered
handlers (applies.htaccess
configuration, rewrites URL, and so
on). In 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. - After the request is processed by all registered handlers, it reaches
mod_aclr2. The handler checks for the X-Accel-external header
presence. If the header is present, the module sends to nginx a
response with zero content length and the X-Accel-Redirect header.
This header contains the exact location of the file as determined by
mod_aclr2. - Once nginx receives the response, it locates the file and delivers it
to the client.
The diagram below is an example of how Plesk handles a request for a 2
KB GIF file.
<…