Just a quick update, I thought I might as well share the scripts I use to create vhosts, so if you are using the setup I described in the other blog posts, this will make life easier for you, else just modify it to suit your needs.
vhost.sh (interactive script) – Screenshot
#!/usr/local/bin/bash
# vhost script by miklos@microsux.dk
# Apache template file and vhost directory
ATEMPLATE="/usr/local/etc/apache22/template"
AVHOSTDIR="/usr/local/etc/apache22/vhosts"
# nginx template file and vhost directory
NTEMPLATE="/usr/local/etc/nginx/template"
NVHOSTDIR="/usr/local/etc/nginx/vhosts"
dialog --title "Create new vhost" --inputbox "Enter full domainname:" 8 50 2> /tmp/vhost.inputbox
RETVAL=$?
if [ "$RETVAL" == "255" ]; then
rm -f /tmp/vhost.inputbox
kill -SIGINT $$
elif [ "$RETVAL" == "1" ]; then
rm -f /tmp/vhost.inputbox
kill -SIGINT $$
else
DOMAIN=`cat /tmp/vhost.inputbox`
rm -f /tmp/vhost.inputbox
fi
dialog --title "Create new vhost" --inputbox "Enter full path:" 8 70 2> /tmp/vhost.inputbox
RETVAL=$?
if [ "$RETVAL" == "255" ]; then
rm -f /tmp/vhost.inputbox
kill -SIGINT $$
elif [ "$RETVAL" == "1" ]; then
rm -f /tmp/vhost.inputbox
kill -SIGINT $$
else
FILEPATH=`cat /tmp/vhost.inputbox`
rm -f /tmp/vhost.inputbox
fi
PATHFIXED=$(echo $FILEPATH|sed 's/\//\\\//g')
cat $ATEMPLATE|sed "s/PATH/$PATHFIXED/g"|sed "s/HOST/$DOMAIN/g" > $AVHOSTDIR/$DOMAIN
cat $NTEMPLATE|sed "s/PATH/$PATHFIXED/g"|sed "s/HOST/$DOMAIN/g" > $NVHOSTDIR/$DOMAIN
autovhost.sh
#!/usr/local/bin/bash
# vhost script by miklos@microsux.dk
# Apache template file and vhost directory
ATEMPLATE="/usr/local/etc/apache22/template"
AVHOSTDIR="/usr/local/etc/apache22/vhosts"
# nginx template file and vhost directory
NTEMPLATE="/usr/local/etc/nginx/template"
NVHOSTDIR="/usr/local/etc/nginx/vhosts"
if [ "$1" == "" ]; then
echo "You need to supply domain and path - fx. autovhost.sh test.com /usr/local/www/test.com"
elif [ "$2" == "" ]; then
echo "You need to supply domain and path - fx. autovhost.sh test.com /usr/local/www/test.com"
else
PATHFIXED=$(echo $2|sed 's/\//\\\//g')
cat $ATEMPLATE|sed "s/PATH/$PATHFIXED/g"|sed "s/HOST/$1/g" > $AVHOSTDIR/$1
cat $NTEMPLATE|sed "s/PATH/$PATHFIXED/g"|sed "s/HOST/$1/g" > $NVHOSTDIR/$1
fi
Apache template file
<VirtualHost 127.0.0.1:8080>
DocumentRoot "PATH"
ServerName HOST
ErrorLog "/var/log/apache/HOST-error_log"
CustomLog "/var/log/apache/HOST-access_log" common
<Directory PATH>
AllowOverride None
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
nginx template file
server {
listen 84.246.242.141:80;
server_name HOST;
error_log /var/log/nginx/HOST-error.log;
access_log /var/log/nginx/HOST-access.log main;
location / {
proxy_pass http://127.0.0.1:8080;
include /usr/local/etc/nginx/proxy.conf;
}
}
Enjoy!
#1 by Bionix on 18. February, 2011 - 21:00
Quote
Hi,
very good stuff at your site.
I read your blog posts and found a littel mistake at this site.
The url for the second screenshot is not the right link.
Bye,
Bionix
#2 by Miklos on 21. February, 2011 - 21:33
Quote
You are absolutely right – thank you for pointing that out 🙂
I removed the duplicated screenshot 🙂