'auto'rewrite link to a folder

Francis Daly francis at daoine.org
Thu Aug 14 09:01:14 UTC 2014

On Thu, Aug 14, 2014 at 09:12:39AM +0200, Pascale Camille wrote:

Hi there,

> i confirmed it used to work greatly
> i was working as teacher and needed subdomain easy
> create or delete in one minute!
> avoiding me to do subdomain process...
> (no database site)

I don't see how what you provided could ever have worked as you describe.

However, that does not matter: the following skeleton seems to work for
me; add the rest of your config in as needed:


$ mkdir -p /tmp/www/{one,two,three}
$ for i in /tmp/www/{one,two,three}; do
 echo "content of $i/index.html" > $i/index.html; done

nginx.conf server block:

  server {
    server_name ~^(?P<user>.+).example.com;
    root /tmp/www/$user;

Note that I use the "(?P<" syntax for the named capture; that's what my
pcre engine needs.

Then test:

$ curl -H Host:one.example.com http://localhost/
content of /tmp/www/one/index.html
$ curl -H Host:two.example.com http://localhost/
content of /tmp/www/two/index.html
$ curl -H Host:nil.example.com http://localhost/

which gives "404 Not Found", as expected.

Francis Daly        francis at daoine.org

More information about the nginx mailing list