Setup Nginx as web server and as reverse proxy for Apache with Virtualmin support

Sorry, this entry is only available in Brazilian Portuguese. For the sake of viewer convenience, the content is shown below in the alternative language. You may click the link to switch the active language.

We know that Nginx is more faster than Apache and most of us prefer to replace Apache with Nginx as their web server. Nginx is known to serve faster static content and run with less RAM. As of this writing, Virtualmin supports Apache as its web server. To take advantage of Nginx, we will install it as reverse proxy for Apache and continue using Virtualmin to manage your domains. This guide also applies to Nginx+PHP FPM setup just skip the “Configure Apache” section and skip the “Configure Virtualmin” section if you are not using Virtualmin. Nginx configurations for virtual host are tailored for Drupal site and the following are the features:

The following procedures are tested on Linode server running Centos 7 64-bit Linux distribution.

Install Nginx

If you need to install Nginx with PageSpeed module please follow the steps here instead then jump to configure Nginx section.

  1. In able to install the latest Nginx server we will need to register Nginx repository:
    Have the following codes as its content:
    Note: if just in case the nginx does not install try to hard code the $releasever with value of 7
  2. Install Nginx using yum:
  3. Make Nginx auto-start upon reboot:

Configure Nginx

  1. We will not need the native Nginx configurations provided because we will create new configurations. Lets backup the original Nginx configurations first:
  2. Create the folders following the directory structure shown below:Nginx folder structure

    In the next steps, we will populate these folders with Nginx configurations. We will start populating each folder from bottom folder (utils) to top folder (apps).

  3. Create the main Nginx file /etc/nginx/nginx.conf and copy the following scripts to this file:

    Create the file /etc/nginx/drupal/php_handler.conf and add the following to it:

    We have two options here: microcache_auth.conf which uses the Nginx cache for anonymous users only and microcache.conf which uses the Nginx cache for both anonymous and authenticated users. The microcache_auth.conf is enabled by default. Select between the two according to your requirements.

    Create the file /etc/nginx/drupal/named_location.conf and add the following to it:

    Create the file /etc/nginx/drupal/drupal_upload_progress.conf and add the following to it:

    Create the file /etc/nginx/drupal/drupal_install.conf and add the following to it:

    Create the file /etc/nginx/drupal/drupal_cron_update.conf and add the following to it:

    Create the file /etc/nginx/drupal/core.conf and add the following to it:

    Create the file /etc/nginx/drupal/common_server_context.conf and add the following to it:

    Create the file /etc/nginx/drupal/boost.conf and add the following to it:

    Populate the /etc/nginx/apps/pagespeed folder under this guide.

    To enable Google PageSpeed in your Nginx configuration (make sure first that your Nginx is compiled with PageSpeed module), uncomment the line seen below at /etc/nginx/nginx.conf:

    … also uncomment the line seen below at /etc/nginx/apps/drupal/common_server_context.conf:
    … and uncomment the line seen below at /etc/nginx/site-available/template.conf:
  4. To enable this Nginx reverse proxy for Apache setup, execute the following:
    On the other hand, if PHP FPM backend is your setup, execute the following:
  5. Set permission:
  6. Restart Nginx:

Setup Nginx requirements

  1. In this tutorial the Apache will use port 8080 and lets open this port to become accessible:
  2. Create the Nginx cache path folder:
  3. Create Nginx logrotate script: