By default, the Apache web server works in conjunction with nginx. The benefits are that web pages load faster and server resources are saved. To learn how Apache and nginx collaborate by default, see Apache with nginx.

For any website, you can change the default method of Apache and nginx collaboration. More exactly, you can:

  • Specify whether nginx must work as a proxy for Apache or as an independent server for handling all HTTP requests to websites.
  • Specify which type of web content (static or dynamic) must be processed by each of the servers if you use nginx as a proxy server.

Such settings can help optimize the performance of highly loaded web applications that have a lot of dynamic content (PHP files) or a lot of static content.

The corresponding UI options are available in the Customer Panel in Websites & Domains > <domain_name> > Apache & nginx Settings.

Note: nginx-related settings are available only if nginx is turned on.

The diagrams below show all the possible configurations for Apache working in conjunction with nginx, and provide comments on pros and cons of each configuration. Note that if you use nginx alone, no requests can reach Apache.

Processing Static Content

The following table shows how Plesk handles the request for a 2KB GIF image file depending on the nginx configuration.

 
image 71998
 
Smart static files processing is turned on
image 71999

It is the optimal configuration in terms of performance and reliability.

The request is passed to Apache which returns only a file location. The file is located and delivered by nginx.

Smart static files processing is turned off
image 72000

nginx passes requests and responses without modification, which allows using the mode for troubleshooting nginx related issues.

The file is sent twice: from Apache to nginx and from nginx to client. This may slightly reduce the performance especially when delivering large files.

The GIF file extension is included into Serve static files directly by nginx
image 72001

This mode improves performance of delivering static files.

Note that as requests never reach Apache, they do not pass through Apache handlers. This means that, for example, rewrite rules or .htaccess directives will not be applied.

Processing Dynamic Content

The following table shows how Plesk will handle a request for a PHP file depending on the nginx configuration.

 
image 71998
 
Process PHP by nginx is turned off
image 72002

It is the optimal configuration in terms of performance and reliability.

The request is passed to Apache, which executes the file and returns the result.

Depending on the site’s hosting settings, Apache uses one of the following handlers: FastCGI, CGI, or the Apache module. You can also choose the PHP version individually for each site.

Process PHP by nginx is turned on
image 72003

nginx itself executes the file using the PHP-FPM handler. The PHP-FPM handler offers enhanced FastCGI capabilities, which may improve performance of web apps, especially those with many users.

Note that as requests never reach Apache, they do not pass through Apache handlers. This means that some web apps may not operate as expected. Apache .htaccess directives and rewrite rules will not be applied as well.

Note: To make the option Process PHP by nginx available, you should install PHP-FPM support for nginx. For details on installing PHP-FPM support, refer to the section PHP Handlers.

Setting Up Additional nginx Directives

To add custom nginx directives for a website, use the Additional nginx directives field. When editing the field, use the syntax as in nginx.conf. For example, if you want to pack all the proxied requests with gzip, add the line:

gzip_proxied any;

Note that your customers cannot view and edit the Additional nginx directives field.