New website custom defaults

Ramiro J. Gómez Massetti 9 years ago updated by JBI 3 years ago 12
Hi, it will be nice to have an option to set custom defaults when we create a new website in Ajenti V.
Cases of use:
1- We have a particular directory structure: /home/www/websitename/public_html but when we create a new website the default root is /srv/new-website and we have to change the root directory manually to fit our structure. The ideal situation is to be able to configure a default directory using wildcards replacement. Example: /home/www/%websitename%/public_html
2- Another example is the custom nginx config. We have an nginx conf file that applyes a generic config in terms of static files caching, security rules, etc., this file is located in /etc/nginx.templates.d/genericrules.conf and in every new website created we include that file writing: 
include /etc/nginx.templates.d/generic_vhost.conf;
in custom conf in advance tab.
It would be great to be able to configure a default value.
3- It would be interesting also to configure the possibility that when you create a new site, also create a php pool with certain parameters.

Thx for all !
Yeah, completely agree. I think that point 2 needs an extension though: For every file in /etc/nginx.templates.d/*.conf make a checkbox with filename as checkbox name. IE: I have files /etc/nginx.templates.d/wordpress.conf and /etc/nginx.templates.d/drupal.conf. Ajenti should create checkboxes "Wordpress" and "Drupal" (capitalize first letter).
I have a solution for your suggestion number one:
  1. Find file "api.py" (path /var/lib/ajenti/plugins/vh/api.py on my CentOS 6 system)
  2. Edit line 41, replace '/srv/new-website' with '/var/'+j['name'], so the whole line should look like this: self.root = j.get('root', '/var/'+j['name']) instead. (you can also modify it to your own needs. you can add +'/public_html' at the end of bracket, like this '/var/'+j['name']+'/public_html')
  3. Save file and restart Ajenti.
This will change the default template directory. Just beware that after an update package manager will most likely replace this file, so you would have to do it again.
I also highly recommend you to backup the original file in case you made a mistake like missing ', so you can revert it back.

Solution for suggestion number two is to edit the same file as above, and just 2 lines below we have
self.custom_conf = j.get('custom_conf', '').
Now, we can insert our custom-default conf here.
self.custom_conf = j.get('custom_conf', 'include /etc/nginx.templates.d/generic_vhost.conf;')
Thanks Filip !!, this is an excellent solution.
I know almost nothing about Python, so your help served me a lot.

awesome flip, what about self.custom_conf for apache? what should i include there for the default template configuration?

May I suggest to move line 45 "self.slug=..." just after line 32 "self.name=..." and then in line 42 replacing with j.get('root', '/var/www/'+self.slug+'/public_html') or anything else than /var/www but you get a slugged path, compliant with nginx.

Thanks for the original trick !

Hi, How can I change it to display the username like: /srv/[username]/new-website

thanks in advance

[root@web01 plugins]# grep server_name /var/lib/ajenti/plugins/vh-nginx/nginx.py
'server_name': (
'server_name %s;' % (' '.join(domain.domain for domain in website.domains))

Does anyone know how to adjust this so that it automatically adds the www subdomain to each vhost?  Right now I need to add the www as a separate domain in Ajenti for each domain added.

Should look like

server_name www.example.com example.com;
I looked into your issue a little bit.
The way ajenti website creation works, it isn't possible. When you create a new page, you enter website name only (identificator), not server_name (domain), that is "example.com" by default. I could tell you, how to set server_name to website name and then add www to it automatically, though.
The vhost file doesn't actually get created when you create a new page, though, but only when you actually assign a domain to a page. Ramiro's point about how this would automatically add a www.subdomain.example.com to each subdomain, is a good one. I'll just keep adding them manually for the time being. Thanks.
Hi Teeps, i think a "add www" when creating domain name would be a nice feature. I would not know to do to add it automatically, and also I would not like it so.. because the "www" well be added to subdomains too.
I'm also having some trouble -- I have successfully created a couple of websites but when I try to open them I am getting content from /var/www instead of the directories set up in Ajenti (/svr/...). I am not sure what to do at this point. Thanks
Restart nginx:
  • sudo systemctl restart nginx - CentOS 7, ArchLinux
  • sudo service nginx restart - Ubuntu, Centos 6.x, Debian
If that doesn't work, check your configuration - If you have domain properly configured etc