Reputation: 404
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?
Upvotes: 1
Views: 979
Reputation: 404
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)
Upvotes: 1
Reputation: 14354
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
.
Upvotes: 3