How to create a subdomain in VestaCP

Visiting the VestaCP panel support forum, I noticed that often users ask how to create a subdomain in VestaCP. In fact, it is very simple.First you need to go to the panel itself:

Panel Login


Next, we need to go to the WEB tab:

Go to the WEB tab


Click the Add WEB domain button:

Adding a Domain


In the Domain field, enter the name of your subdomain (for example, if your site is domain.tld, then the subdomain name will be sub.domain.tld). I decided to leave all other parameters unchanged:

Adding a Domain


Now, when we return to the WEB tab, we will see that our subdomain is now in the list of domains:

Result


This completes the subdomain addition.

An interesting feature of VestaCP is that a separate folder is created for subdomains. This does not suit some users, so they wonder if it is possible to make the subdomain use the folder from the main domain (for example, domain.tld is the sub directory, that is, domain.tld / sub). This issue can be resolved by editing the domain configuration files. I note that CentOS is installed on my server.

To do this, we need to connect to the server using SSH:

ssh user@your.server

Next, we need to go to the folder with the virtual host configuration files:

cd /home/$user/conf/web

where $ user is your username. Next, you need to create (use the touch filename command ) the httpd.sub.domain.tld.conf, nginx.sub.domain.tld.conf, shttpd.sub.domain.tld.conf, snginx.sub.domain.tld.conf and edit with an editor convenient for you (the last two if you are using a secure SSL connection on your site).

Create the httpd.sub.domain.tld.conf file with the following contents:

DocumentRoot /home/admin/web/domain.tld/public_html/sub

For a secure connection, create the shttpd.sub.domain.tld.conf file, and perform a similar operation.

We also create the nginx.sub.domain.tld.conf file and add it to it:

root           /home/$user/web/domain.tld/public_html/sub;

For a secure connection, create the snginx.sub.domain.tld.conf file, and repeat the steps.

After editing the files, the main thing is to save the changes. To check everything is done correctly, you need to restart HTTPd and Nginx:

service httpd restart & service nginx restart

and visit our subdomain.

For Debian / Ubuntu, the file name is different - instead of httpd there will be apache2, i.e. apache2.sub.domain.tld.conf. The service reboot command is also different:

/etc/init.d/apache2 restart & /etc/init.d/nginx restart

That's all.

Also popular now: