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!

Did you like this? Share it: