Apache VirtualDocumentRoot for wildcard virtualhosts

<VirtualHost *:80>
    UseCanonicalName Off
    VirtualDocumentRoot /mnt/projects/%1/public
    ServerName subdomains.starfall.local
    ServerAlias *.starfall.local
</VirtualHost>

<Directory /mnt/projects/*/public>
    Options Indexes FollowSymLinks
    AllowOverride All
    Order allow,deny
    Allow from all
</Directory>

Now you might run into infinite redirect issue if use together with mod_rewrite. Add this line in the mod_rewrite .htaccess file for each folder under /mnt/projects to stop this.

RewriteBase /

Update:
The similar effect can be achieved via mod_rewrite. Put this into /etc/apache2/httpd.conf, or apache2.conf but it needs to be loaded first before virtualhost/conf.d. The point here is to let virtualhost config to override this wildcard.

<VirtualHost *:80>
    UseCanonicalName Off
    RewriteEngine On
    RewriteCond %{REQUEST_URI} !^/icons/
    RewriteCond %{HTTP_HOST} ^(.*)\.starfall.local$
    RewriteRule ^/(.*)$ /mnt/projects/%1/public/$1
</VirtualHost>

You may still need to add “RewriteBase /” in case of infinite redirect.

From what I tested this new method handles:
– allow wildcard request to point to /mnt/projects/SUBDOMAIN_NAME/public
– it doesn’t not interfere with subsequent rewrite rule usually present in .htaccess

Achieve wildcard custom domain via Automatic Proxy Configuration

Update: This method seriously screws up apache server variables, namely, REQUEST_URI and DOCUMENT_ROOT. It is recommmended to only use this pac method when you know you don’t need correct REQUEST_URI and DOCUMENT_ROOT.

This allows to point multiple wildcard domain names (canonical or not) to a particular ip or hostname.

First create a Automatic Proxy Configuration file say wildcard.pac, which is basically a javascript file:

function FindProxyForURL(url, host)
{
    if (dnsDomainIs(host, ".customhost.local")) {
        return "PROXY customhost";
    }
 
    return "DIRECT";
}

Note:
“.customhost.local” is basically the pattern to detect
The “customhost” in “return “PROXY customhost”;” is whatever solvable hostname you want, or it can be an ip.

You can use this to config multiple local fake domain names for development purpose, pointing them (e.g. project1.myhost.local, project2.myhost.local to an apache server at 192.168.1.2).

Now to load this pac file, each browser/os is slightly different.
Safari/IE/Chrome: use system network setting, just find the Automatic Proxy Configuration and load the pac file just created.
Firefox/Opera: use their own network config in Preferences

Config Mac OSX Lion’s Samba share

smb.conf no longer work. The actual configuration is stored at /System/Library/LaunchDaemons/com.apple.smbd.plist

To make Lion’s samba share follow symbolic link, you need to modify “ProgramArguments”
from:

<key>ProgramArguments</key>
<array>
     <string>/usr/sbin/smbd</string>
</array>
</code>

to:

<key>ProgramArguments</key>
<array>
     <string>/usr/sbin/smbd</string>
     <string>--no-symlinks</string>
     <string>false</string>
</array>

Push local git repo to a remote server

So this is how to put local repository onto a remote “central” version control repository:

On remote server (note the “–bare” is important otherwise you won’t be able to push):

mkdir /home/vincent/projects/repo.git
cd /home/vincent/projects/repo.git/
git init --bare

On local, cd into the local repo directory first

git remote add origin ssh://username@remoteserver/home/vincent/projects/repo.git
git push origin master

In future you can just clone:

git clone ssh://username@remoteserver/home/vincent/projects/repo.git