NOTE: This script has been superseded by this one: Bash Script to Create new virtual hosts on Nginx each under a different user
Setting up virtual hosts on any sort of web server normally takes at least a few minutes and several commands (if you’re not running a control panel of some variety, and even then it normally takes a good number of clicks and checking boxes to get what you want). All of this can be quite annoying when you have to set up several of these a day.
So I put together a simple bash script to quickly provision the hosting for a new static site running on Nginx. The script was originally build for use on the Amazon AMI running on AWS. The script uses the sudo command as the password is not required for the default user on the AWS AMI, however if you are running as a non root user with access to the sudo command then you should be prompted for your password when running the script.
What does the script do:
- Creates a new vhosts entry for nginx using a basic template
- Creates a new directory for the new vhost and sets nginx as the owner
- Adds a simple index.html file to the new directory to show the site is working.
- Reloads Nginx to allow the new vhost to be picked up