Customize NGINX® with Reverse Proxy Configurations

Last modified: 2025 February 10


Overview

You can customize NGINX® with reverse proxy in a number of ways.

Global Configuration settings

You can set the following directives for NGINX in WHM’s Global Configuration interface (WHM » Home » Service Configuration » Apache Configuration » Global Configuration). The following values in the Global Configuration interface correspond to the following directives:

  • Keep-Alive — This directive corresponds to the keepalive directive. If you set this value to On, NGINX uses a value of 32. If you want to use a different value, set the keepalive value to a valid number in the /etc/nginx/ea-nginx/settings.json file.
  • Keep-Alive Timeout — This directive corresponds to the keepalive_timeout directive. NGINX only uses the value set in WHM’s Global Configuration interface.
  • Max Keep-Alive Requests — This directive corresponds to the keepalive_requests directive. NGINX only uses the value set in WHM’s Global Configuration interface.
    Note:
    If you set this value to Unlimited in the Global Configuration interface, then NGINX uses a value of 1000.

Global configuration files

Place any global .conf files that you create in the /etc/nginx/conf.d/ directory.

For example, if you want to adjust every server block on your server, create your .conf file in the /etc/nginx/conf.d/server-includes/ directory.

Note:

Make certain that you also reference your .conf file with an include directive in the file that you want to use it in.

Server blocks

If you want to customize the server blocks for NGINX, create an include file that ends in .conf in the appropriate location. A server block is the same thing as a virtual host in Apache.

Each server block will include the .conf files in the /etc/nginx/conf.d/server-includes/ directory.

For more information about server blocks, including examples, read NGINX’s Serving Static Content documentation.

Note:

Do not use cpanel- as the prefix for any custom files you create.

User configuration

Note:

In the following examples, username represents the username, and domainname represents the fully-qualified domain name.

This fully-qualified domain name must be one of the following:

  • The server block’s main domain.
  • The server block’s subdomain for addon domains and their subdomains.
  • The server block’s subdomain for subdomains that are not addon domains.

To customize every server block that a user owns, create your .conf file in following directory:

/etc/nginx/conf.d/users/username

To customize a specific server block for a specific domain, create your .conf file in the following directory:

/etc/nginx/conf.d/users/username/domainname/

Custom server configurations

Warning:
  • Do not edit any of the files that NGINX owns. Changing these files may result in unexpected behavior.
  • If you create custom configuration files, you may change NGINX behavior in undesired ways. For example, if your custom block matches the PHP block, the server may serve the source code instead of PHP.

To customize your NGINX configuration before you install the ea-nginx package, you can create the following files:

  • /var/nginx/ea-nginx/settings.json
  • /var/nginx/ea-nginx/cache.json
Important:

If these files exist when you install NGINX or rebuild your NGINX configuration, the system will copy them to the /etc/nginx/ea-nginx/settings.json and /etc/nginx/ea-nginx/cache.json files respectively, then delete the /var/nginx/ea-nginx/settings.json and /var/nginx/ea-nginx/cache.json files. You can also edit the /etc/nginx/ea-nginx/settings.json and /etc/nginx/ea-nginx/cache.json files directly after you install NGINX.

We also support the following directives in the /var/nginx/ea-nginx/settings.json file:

For more information about how to set keepalive_time values in WHM’s Global Configuration interface (WHM » Home » Service Configuration » Apache Configuration » Global Configuration), read the Global Configuration settings section.

Important:

If you create these files, they must contain valid JSON. Invalid JSON files may cause your installation to fail.

Restrict file access

You can restrict file access by creating a .conf file in the appropriate location and adding exclusion commands to it. For example, if you serve your website from a git repository, you may want to prevent access to the site’s .git directory, you would add the following commands to a .conf file placed in the appropriate location:

1
2
3
4
5
6
location ~ /\.git {
       deny all;
       log_not_found off;
       access_log off;
       return 404;
   }  

After you save the file, reload your server to activate the configuration change.

For more information, read the NGINX Location Priority documentation.

Increase NGINX worker processes

To increase the maximum number of worker processes NGINX can run at one time, increase the worker_processes value. To do this, perform the following steps:

  1. Open the /etc/nginx/ea-nginx/settings.json configuration file with your preferred text editor. We strongly suggest making a backup copy of the file before proceeding.
  2. Locate the line that contains the worker_processes value. The line will resemble the following example:
     worker_processes 1 
  3. Increase the value.
    Note:
    If you do not have a target value, we recommend doubling the current value.
  4. Save your changes, then run the following command:
     nginx -t 
    If you receive a message that resembles the following example, you have successfully updated your configuration:
     nginx: the configuration file /etc/nginx/ea-nginx/settings.json syntax is ok
    nginx: configuration file /etc/nginx/ea-nginx/settings.json test is successful 
    If you do not, check that you have only updated the worker_processes value, and not any formatting.
  5. Restart NGINX.

Your worker processes will now be able to keep more connections open at one time.

Add the X-Cache-Status header to NGINX responses

To track which responses are being served from your cache, add the X-Cache-Status header to NGINX responses with the following steps:

  1. Open the /etc/nginx/ea-nginx/cache.json file with your preferred text editor.
  2. Locate the x_cache_header value. It will resemble the following example:
     "x_cache_header": false, 
  3. Edit the x_cache_header value to be true, as follows:
     "x_cache_header": true, 
    Important
    Do not remove the comma (,) when you edit the value.
  4. Rebuild NGINX with the Rebuild Configuration option in WHM’s NGINX Manager interface (WHM » Home » Software » NGINX Manager).

Your responses will now contain an $upstream_cache_status that will help you determine how your server is responding to queries. To learn more about this status and what it means, read NGINX’s Caching Guide.