Semi-automating Nginx server block set up on Ubuntu with a script?
First of all, thanks for this great tutorial: https://www.digitalocean.com/community/tutorials/how-to-set-up-nginx-server-blocks-virtual-hosts-on-ubuntu-14-04-lts
I’m following it to manually create server blocks for multiple domains on the same server.
I can’t help but think I could be saving time by writing a script one time and running a command like “myscript domainnamehere.com” which would end up doing all of the steps for me. Here’s what I currently do:
- sudo mkdir -p /var/www/domainnamehere.com/html
- sudo chown -R $USER:$USER /var/www/domainnamehere.com/html
- sudo cp /etc/nginx/sites-available/default /etc/nginx/sites-available/domainnamehere.com
- sudo nano /etc/nginx/sites-available/domainnamehere.com to add references to the directory made it step #1 and add the domain name to look for next server_name.
- sudo ln -s /etc/nginx/sites-available/domainnamehere.com /etc/nginx/sites-enabled/
Obviously #1 and #2 is easy, but #3 and #4 is where I think things can be made more efficient.
Also I know I probably don’t need to use the cp command to copy the site configuration over, it would probably make more sense if the sample file was included in the script so it could easily write to a file with the proper domain name variables.
How would I develop a script that could take an argument (the domain name) and do all of the above for me?
Does this make sense at all? Let me know if you need any clarification about anything. Any pointers would be greatly appreciated!