This section will help you to create a custom vhost or app template for your cpnginx server . Cpnginx uses the python Mako template language . You may read the template file documentation of Mako properly .

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

#:keyword:Description of the Template:version number:

An example is given below,

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

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

Please see the location of template files below,

/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.

Cpnginx run nginx in three different modes called hybrid, proxy and nginx. This 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 infront of apache
nginx.conf – It is a stand alone nginx with multi-php fpm

Don’t edit this 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 

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

The default app templates located on /etc/cpnginx/templates/apps/ . You can see wordpress.conf, joomla.conf,etc,. These are the cpnginx provided app template. Don’t edit this 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 

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

If you need to create a different template for an app or a specific domain , we recommend to clone 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 own custom template from nginx.conf with the name "yourhost"

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

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

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

Now edit the 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 from whm and cpanel.

Cpnginx have extended features to manage your templates from whm itself. You can clone, edit or upload a template from whm cpnginx page itself.

Cpnginx pass the template variables as a dictionary to the specific template files . Each template must contain an SSL and NON-SSL part.The following are the template variables .

Template Variable Value(s) Description
HAVESSL 0 , 1 For ssl and non-ssl template blocks
HAVE_DEDICATED_IP 0 , 1 For dedicated IP
TYPE main,sub,park,addon Type of the domain
DOMAIN Website The domain name
DOCROOT Path The document root of the domain
IP Ip address IP address of the domain
USER The cpanel user The cpanel user name of the domain owner
APACHE_HTTP_PORT 9080 The http port of apache , or lightspeed
APACHE_HTTPS_PORT 9443 The ssl port of apache , or lightspeed
PARENT_DOMAIN The associated domain Using for parked domains
STATIC_FILES Extensions Static file extension serving from nginx
WWW_REDIRECTION none,nontowww,wwwtonon WWW and Non-WWW redirections
SLOWLORIS_DOS 0, 1 Slow-loris ddos protection
SYMLINK_ATTACK on,off Symlink protection
DIRECTORY_LIST 1 , 0 Enable or disable directory listing
MOD_FLV 1,0 Enable or disable flv streaming
MOD_MP4 1,0 Enable or disable mp4 streaming
MAX_BODY_SIZE 2000m Nginx variable
BODY_BUFFER_SIZE 512k Nginx variable
USERDIR_STATUS 1,0 Enable or disable nginx userdir
DIRECTORY_LIST 1,0 Enable or disable nginx directory list
HOT_LINK_PROTECTION 1,0 Enable or disable Hot link protection
PROXY_BUFFERING on,off Nginx variable
PROXY_SEND_TIMEOUT 300s Nginx variable
PROXY_READ_TIMEOUT 300s Nginx variable
PROXY_BUFFER_SIZE 64k Nginx variable
PROXY_BUFFERS 32 64k Nginx variable
PROXY_BUSY_BUFFERS_SIZE 128k Nginx variable
PROXY_TEMP_FILE_WRITE_SIZE 128k Nginx variable
PROXY_CONNECT_TIMEOUT 300s Nginx variable
PROXY_HTTP_VERSION 1.1,1.0 Nginx variable
PROXY_SET_HEADER_CONNECTION 0,1 Set the proxy header Connection
PROXY_CACHE 1,0 Enable or disable proxy cache
PROXY_CACHE_REVALIDATE On,off Nginx variable
PROXY_CACHE_MIN_USES 5 Nginx variable
PROXY_CACHE_LOCK on,off Nginx variable
PROXY_CACHE_VALID 60h Nginx variable
PROXY_CACHE_USE_STALE 0,1 Nginx variable
FASTCGI_CACHE 1,0 Enable or disable php-fpm fcgi cache
FASTCGI_CACHE_VALID 30m Nginx variable
FASTCGI_CACHE_LOCK 1,0 Nginx variable
FASTCGI_CACHE_USE_STALE 1,0 Nginx variable
SSL_PROTOCOLS TLSv1 TLSv1.1 TLSv1.2 Allowed ssl protocols
HTTP2 1,0 Enable or disable http2
HTTPS_REDIRECTION 1,0 Enable or disable http to https redirection
GOOGLE_PAGE_SPEED 0,1 Enable or disable google page speed
LIMIT_CONN 1,0 Enable or disable nginx limit_conn
LIMIT_CONN_PERCLIENTIP 10 Limit connection per IP
LIMIT_CONN_PERVIRTUALSERVER 100 Limit connection to vhost
REQ_MODULE 1,0 Enable or disable nginx req module
LIMIT_REQ_PERCLIENTIP 10 Limit request per IP
LIMIT_REQ_PERVIRTUALSERVER 100 Limit request per vhost
CLIENT_BODY_TIMEOUT 180s Nginx variable
RANGE_PROTECTION 1,0 Enable or disable range based attacks
HTTP_METHOD_ENABLE 1,0 Enable or disable http methods (HEA,GET,POST)
USER_AGENT_ATTACK_PROTECTION 1,0 Enable or disable user agent attack protection
SCANNER_ATTACK_PROTECTION 1,0 Enable or disable scanner attacks
XSS_PROTECTION 1,0 Enable or disable xss attacks
XFRAME_ATTACK_PROTECTION 1,0 Enable or disable X-Frame attacks
PROTECT_SQL_INJECTION 1,0 Enable or disable sql injection attacks
PROTECT_FILE_INJECT 1,0 Enable or disable file injection
PROTECT_COMMON_EXPLOITS 1,0 Enable or disable common exploit attacks
REFERRER_SPAM_PROTECHTION 1,0 Enable or disable referrer spams
KEEPALIVE_REQUEST 100 Nginx variable
KEEPALIVE_TIMEOUT 60s Nginx variable