Skip to content

Instantly share code, notes, and snippets.

@AD7six
Last active August 29, 2015 14:11
Show Gist options
  • Save AD7six/04d448f1cd335e218ab9 to your computer and use it in GitHub Desktop.
Save AD7six/04d448f1cd335e218ab9 to your computer and use it in GitHub Desktop.
Don't think of doing this kind of thing on a live box
set $site $host;
# Strip www. prefix
if ($site ~ "^(w{3}\.)?(.*)$") {
set $site $2;
}
# Strip TLD prefix
if ($site ~ "^(.*)(\.[a-z]{3})$") {
set $site $1;
}
# Set webroot based on the domain name i.e. $site is `example` for the domain `www.example.dev`
set $webroot /var/www/$site/public;
# Webroot for this domain could not be found
if (!-d $webroot) {
set $webroot /var/www/default;
}
root $webroot;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment