How to Change Default Vhost Config Template for Nginx?


👉 Divi Builder drag/drop page builder for WordPress

Here is a problem that we encountered when trying to update our Nginx software: the update was simply overwriting our custom Nginx rules, many of which were created to stop folks from messing with our sites. We use cPanel to manage our domains but were manually updating vhost config files for our domains. Updating them over and over again when you have a couple of sites is not tough. But if you have more than a dozen of sites, the process becomes time-consuming. You just have to find the “createvhosts.py” files to address the issue.

In our case, the file is located in our scripts directory (scripts/createvhosts.py). Those of you who know your Nginx are going to find the file pretty easy to read. As you can see in the above example, there is no need to hard-code your IP (“%s” takes care of that). Things are a bit different for those of you who want tn ban certain IPs from accessing specific files and directories on your site.

Before making changes to your files, make sure you back them up. When you are done, you can rebuild your vhosts by going to: WHM -> Plugins -> Nginx Admin -> Rebuild Vhosts. Needless to say, you can build very sophisticated templates with this approach, but you have to know what you are doing.

More WordPress reading: