Customize NGINX® with Reverse Proxy Configurations
Last modified: 2025 February 27
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
keepalivedirective. If you set this value toOn, NGINX uses a value of32. If you want to use a different value, set thekeepalivevalue to a valid number in the/etc/nginx/ea-nginx/settings.jsonfile. - Keep-Alive Timeout — This directive corresponds to the
keepalive_timeoutdirective. NGINX only uses the value set in WHM’s Global Configuration interface. - Max Keep-Alive Requests — This directive corresponds to the
keepalive_requestsdirective. NGINX only uses the value set in WHM’s Global Configuration interface.Note:If you set this value toUnlimitedin the Global Configuration interface, then NGINX uses a value of1000.
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.
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.
Do not use cpanel- as the prefix for any custom files you create.
User configuration
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/usernameTo 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
- 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
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:
keepalive_timeNote:No Apache equivalent exists for thekeepalive_timevalue.worker_shutdown_timeoutworker_processes
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.
If you create these files, they must contain valid JSON. Invalid JSON files may cause your installation to fail.
Manage Cloudflare configuration
By default, NGINX configures Cloudflare® proxies in your /etc/nginx/conf.d/users/example.conf file.
To disable this configuration and exclude Cloudflare® proxies from your /etc/nginx/conf.d/users/example.conf file, add the include_cloudflare directive to your /etc/nginx/ea-nginx/settings.json file and set it to 0 or false - for example, include_cloudflare: false. Then, save the file and restart NGINX with one of the following methods:
- Rebuild NGINX with the Rebuild Configuration option in WHM’s NGINX Manager interface (WHM » Home » Software » NGINX Manager).
- Run the
/usr/local/cpanel/scripts/ea-nginx configscript. You must use the--alloption.
If you do not add the include_cloudflare directive or set it to 1 or true before restarting NGINX, the system will automatically configure Cloudflare proxies in your /etc/nginx/conf.d/users/example.conf file.
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:
|
|
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:
- Open the
/etc/nginx/ea-nginx/settings.jsonconfiguration file with your preferred text editor. We strongly suggest making a backup copy of the file before proceeding. - Locate the line that contains the
worker_processesvalue. The line will resemble the following example:worker_processes 1 - Increase the value.
Note:If you do not have a target value, we recommend doubling the current value.
- Save your changes, then run the following command: If you receive a message that resembles the following example, you have successfully updated your configuration:
nginx -tIf you do not, check that you have only updated thenginx: the configuration file /etc/nginx/ea-nginx/settings.json syntax is ok nginx: configuration file /etc/nginx/ea-nginx/settings.json test is successfulworker_processesvalue, and not any formatting. - 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:
- Open the
/etc/nginx/ea-nginx/cache.jsonfile with your preferred text editor. - Locate the
x_cache_headervalue. It will resemble the following example:"x_cache_header": false, - Edit the
x_cache_headervalue to betrue, as follows:"x_cache_header": true,ImportantDo not remove the comma (,) when you edit the value. - 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.