Hi everyone,
I made my custom template, but I need to add some custom code in the http block and I’d like to do so as a custom file with an include. How can I do that and deploy the same changes to all sites?
Hi everyone,
I made my custom template, but I need to add some custom code in the http block and I’d like to do so as a custom file with an include. How can I do that and deploy the same changes to all sites?
Hi @Ade
If a script named templateName.sh exists in the same directory as your template and has execution permissions, Hestia will execute it, allowing you to add any custom actions you want.
Example of a script that creates a config file named nginx.conf_myinclude and also creates a symbolic link nginx.ssl.conf_myinclude pointing to it.
#!/usr/bin/env bash
user="$1"
domain="$2"
ip="$3"
home_dir="$4"
docroot="$5"
base_dir="${home_dir}/${user}/conf/web/${domain}"
ngx_inc="${base_dir}/nginx.conf_myinclude"
ngx_ssl_inc="${base_dir}/nginx.ssl.conf_myinclude"
cat <<EOF > "$ngx_inc"
Here your options
EOF
ln -rsf "$ngx_inc" "$ngx_ssl_inc"
Hey @sahsanu thank you for your reply!
I think that either I didn’t explain properly what I’m trying to achieve, or I haven’t fully understood your suggested solution ![]()
Let me elaborate on what I’m trying to do.
I have my template that I’ve added to Hestia and that is working well, all sites use that, however I’m in need of adding the following code:
map $http_accept $webp_suffix {
default "Standard images";
"~*webp" ".webp";
}
which is something I can only do in nginx.conf (as it must be within the http block). How can I do so that the default nginx.conf has an include to a custom file of mine, or create a template for the default nginx.conf so that I can add that portion of code?
Then you can modify the template and add those map directives outside the server block. Nginx will load the template, and the map directives will be placed inside the http block. (Note: this will cause an error if there are duplicate map directives using the same variable, but you get the idea.)
Or if those options only need to be loaded once, you can add them to /etc/nginx/conf.d/whatever.conf and nginx will load it in http block.
You are totally right, adding the code before the server block seems to have done the trick so I can just edit my template! Thank you @sahsanu!
Can you please remind me the cli command that I can use to reapply the template to all sites in bulk?
Keep in mind that some options can’t be duplicated or Nginx won’t restart.
There isn’t a specific command but you can use this to rebuild all the web domains for all your users:
for i in $(v-list-users plain | awk '{print $1}');do echo "Rebuilding web domains for user $i";v-rebuild-web-domains "$i"; done
All good! Thank you again!
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.