Rewrite rules into Nginx configuration file

Hi,
I added some rewrite rules to /home/user/conf/web/domain.tld/nginx.ssl.conf file. Everything works fine, but the problem is that these changes will be overwritten at the next Hestia upgrade.
The right way to solve this is to create a new template in the /usr/local/hestia/data/templates/web/nginx/ directory.
However there are several templates there:

  • caching (.sh, .stpl, .tpl)
  • default (.stpl, .tpl)
  • hosting (.sh, .stpl, .tpl)
  • proxy_ip.tpl
  1. Which of these files do I have to copy?
  2. Do I have to copy them in the same directory?
  3. Which name should I use for the new templates?
  4. Is there anything else I should set after creating the new templates?

Default template is default.tpl and default.stpl

Yes

Doesn’t matter as long you keep the same extension. .sh allows running some extra code after template activation

Activate the template in edit web domain

See:
https://docs.hestiacp.com/admin_docs/web.html

The template I would need is the same as the “wordpress” one… should I copy the default.tpl template or there’s a specific one for WordPress?

@eris can you pls confirm the above message?

Look at the folder and if you find a wordpress template that’s it if you can’t find it, then you might want to copy default.tpl

@jlguerrero Hola José,
Unfortunately there’s no “wordpress” template there.
I see that under “Edit Web Domain” page in the “Web Template” field there’s a lot of different templates (chevereto, cms made simple, etc…).
Where are located all those templates in HestiaCP filesystem?

BTW I’ve set “wordpress” as template and then I compared the content of both “wordpress” nginx.ssl.conf file and default.stpl and they are totally different… why do you say that default.tpl could be used as a template for WordPress sites?

We are saying that you can rename default.tpl into wordpress.tpl and then you can edit it to fit your particular needs.

After that, it will be available in the server for any user to select.

@eris @ScIT
Ok, but where are located all other templates? (chevereto, cms made simple, etc…)

Where does HestiaCP gather the data to build up let’s say a WordPress nginx.ssl.conf file?

https://docs.hestiacp.com/admin_docs/web.html#how-do-web-templates-work

…

This is an excerpt from nginx.conf file choosing the “wordpress” template:

server {
    listen      IP:80;
    server_name domain.tld www.domain.tld;
    root        /home/user/web/domain.tld/public_html;
    index       index.php index.html index.htm;
    access_log  /var/log/nginx/domains/domain.tld.log combined;
    access_log  /var/log/nginx/domains/domain.tld.bytes bytes;
    error_log   /var/log/nginx/domains/domain.tld.error.log error;

    include /home/user/conf/web/domain.tld/nginx.forcessl.conf*;

    location = /favicon.ico {
        log_not_found off;
        access_log off;
    }
    ..................

and this is an excerpt from default.tlp template:

server {
    listen      %ip%:%proxy_port%;
    server_name %domain_idn% %alias_idn%;
        
    include %home%/%user%/conf/web/%domain%/nginx.forcessl.conf*;

    location / {
        proxy_pass      http://%ip%:%web_port%;
        location ~* ^.+\.(%proxy_extensions%)$ {
            root           %docroot%;
            access_log     /var/log/%web_system%/domains/%domain%.log combined;
            access_log     /var/log/%web_system%/domains/%domain%.bytes bytes;
            expires        max;
            try_files      $uri @fallback;
        }
    }

Content is totally different from one file to the other…

As you are part of the dev team of HestiaCP, can you explain how does Hestia build up the nginx.conf file as the one above?
It must gather the info from somewhere… a file, database data?

How hard it it to follow a link… All the know variables are know it will be replaced during the rebuild of the config phase…

https://docs.hestiacp.com/admin_docs/web.html#available-variables

@eris I didn’t mean the variables but I was talking about the file structure… they are completely different… anyway, I see that’s quite difficult to have detailed explanations on a chat…

Now I created 2 new templates (tpl and stpl) in the /usr/local/hestia/data/templates/web/nginx/ directory.

Following your instructions at Web domains and SSL Certicates — Hestia Control Panel documentation, it says that “After modifying existing template you need to rebuild user configuration”…

To do this, I went to “USERS” page, selected the proper user, from the “Apply to selected” dropdown I selected “Rebuild User Profile” and confirmed.

Now the new template should show up in the “Edit Web Domain > Advanced Options > Web Template” field, right?

But it doesn’t… is there anything else that must be done to make it show in the template list?

If your are using Nginx + PHP-FPM the folder is /usr/local/hestia/data/templates/web/nginx/php-fpm

1 Like

For God’s sake… I totally missed the php-fpm directory… It was there that all templates were stored…

It’s working even if I didn’t rebuild the user profile… is it mandatory to rebuild it?
What’s the purpose of rebuilding it?

If you change a template it will not update until you rebuild the domain. If you edit a website and change the template you do allready the same…

2 Likes