How Apache and Nginx relate
A TurboStack host runs one web server, chosen with the webserver setting. Apache does not sit
behind Nginx: setting webserver: apache2 removes Nginx from the host, and webserver: nginx
removes Apache.
So with webserver: apache2, Apache is the front door. It terminates HTTPS, redirects HTTP to
HTTPS, runs your application over PHP-FPM and reads .htaccess from your document root.
How requests flow
Without Varnish, there is one virtual host and one hop:
- The visitor reaches Apache over HTTPS.
- Apache serves the file, or hands the request to PHP-FPM, applying any
.htaccessrules along the way.
With Varnish enabled, Apache runs twice:
-
The visitor reaches a front virtual host, which holds the certificate and passes the request to Varnish.
-
Varnish answers from its cache, or asks the backend virtual host - a plain Apache on the same machine, without HTTPS.
-
The backend serves the request. This is the virtual host that has your document root, so it is the one that reads
.htaccess.
That second case matters for access rules: anything in .htaccess is only evaluated when a request
reaches the backend, so a page Varnish already holds is served without it. See
Method 3 in Restrict access with basic authentication
for how to apply a rule in front of the cache.
What you configure where
When to choose Apache
Choose Apache when your application depends on .htaccess rules that it ships and maintains itself.
If you do not need .htaccess, Nginx (webserver: nginx) is the lighter default - see
Configure Nginx.