1

With Apache's mod_vhost_alias you can use Directory Interpolation to serve sites based on directory structure. See here http://httpd.apache.org/docs/2.2/mod/mod_vhost_alias.html#interpol

Is this possible with NGINX? if so how?

Keegan 82
  • 394
  • 2
  • 11

2 Answers2

3

The simplest one would be:

server {
    listen 80 default_server;
    root /var/www/$host;
}

For http://www.example.com/directory/file.html this will serve file /var/www/www.example.com/directory/file.html.

Alexey Ten
  • 13,794
  • 6
  • 44
  • 54
1

I've just found out through randomly searching for something else that the exact same functionality as Apache's Directory Interpolation (and more) can be achieved using regex, for example...

server_name "~^(?<machine>.*?)\.(?<domain>.*?)\.(?<group>.*?)\.dev$";
root "/some/place/projects/$group/$domain/$machine";

For anyone coming here wanting to auto manage their local webserver setup, I found these useful to take care of the DNS side of things

https://echo.co/blog/never-touch-your-local-etchosts-file-os-x-again (mac) http://mayakron.altervista.org/wikibase/show.php?id=AcrylicHome (win)

Keegan 82
  • 394
  • 2
  • 11