Is there an NGINX equivalent of Apache's Directory Interpolation

935 views Asked by At

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?

2

There are 2 answers

0
Alexey Ten On BEST ANSWER

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.

0
Keegan 82 On

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)