Skip to main content

Cpnginx Templates

Create and Manage Nginx vhost templates in Cpnginx

This section tells you everything about vhost template or app template management in Cpnginx.

Cpnginx uses the Python Mako template language. You may read the template file documentation of Mako properly.

 First line of the template file

The first line of the template file must be in the following format.

#:keyword: Description of the Template : version number:
  • keyword:  This is the unique keyword of the template name, as it is the same as the template file name.
  • Description of the Template: This is an explanation to show your clients about the template information. This will help to identify what the template is.
  •  version number: This will be a unique version number of your template, which will help you track your template

An example is as follows:

#:nginx:Nginx+ PHP-FPM Default  Stand Alone:1.0:

This first line is important. It used to show the templates in your Cpnginx interface pages and to build the template pools.

Location of templates

Please see the location of template files below:

Item Description
/etc/cpnginx/templates/ The root of all nginx templates
/etc/cpnginx/templates/apps/ Location of default app templates provided by cpnginx
/etc/cpnginx/templates/vhost/ Location of default nginx template, hybrid, vhost, and nginx
/etc/cpnginx/templates/fpm/ The fpm user pool template
/etc/cpnginx/templates/custom/ This is the custom template director for you.

You may only upload or edit templates in the directory /etc/cpnginx/templates/custom/. All other folders will be updated with the default cpnginx templates.

Default Vhost Templates

Cpnginx runs nginx in three different modes: hybrid, proxy, and nginx. These templates are located under /etc/cpnginx/templates/vhost/ .

  • hybrid.conf - Nginx server static files and Apache server dynamic files
  • proxy.conf - Nginx works as a proxy in front of Apache
  • nginx.conf – It is a standalone nginx with multi-php fpm

Don’t edit these template files. If you need to create a custom template for these templates, copy this file to the custom folder and edit it. An example is given below,

cp /etc/cpnginx/templates/vhost/nginx.conf /etc/cpnginx/templates/custom/nginx.conf

In the above example, if you have a custom nginx.conf template in your custom folder, the cpnginx by default uses only that custom vhost template file for the selected domains or subdomains.

Default app templates

The default app templates are located in /etc/cpnginx/templates/apps/ . You can see wordpress.conf, joomla.conf,etc. These are the cpnginx provided app template. Don’t edit these template files. If you need to create a custom template for WordPress, simply copy this file to the custom folder and edit it.

cp /etc/cpnginx/templates/apps/wordpres.conf /etc/cpnginx/templates/custom/wordpress.conf 

In the above example, if you have a custom wordpress.conf template in your custom folder, the cpnginx by default uses only that custom vhost template file for the selected domains or subdomains.

Creating a new template

If you need to create a different template for an app or a specific domain, we recommend cloning one of the basic template options ( hybrid, proxy, or nginx ). So that it is easy to modify it. Please see the example below for creating your custom template from nginx.conf with the name "yourhost".

 # cp /etc/cpnginx/templates/vhost/nginx.conf /etc/cpnginx/templates/custom/yourhost.conf 

Now edit yourhost.conf and update the first line as follows,

#yourhost:This is your host template file :1.0:1

Now edit your yourhost.conf file and make all changes you need. Make sure to follow the mako template syntax properly. After finishing the modification, please run the following command ,

nginxctl templaterebuild 

This command will automatically add your templates to cpnginx, and you can access them from WHM and cPanel.

Upload/ Clone /Edit Templates from WHM 

Cpnginx has extended features to manage your templates from WHM itself. You can clone, edit, or upload a template from the WHM Cpnginx page itself.