andi I believe in nginx you can have something like server_name = .*.example.com
Be aware that .*\.example\.com
will match a.example.com
but also a.b.c.d.example.com
.
Nginx can use wildcard servername or plain regexp. As per nginx documentation, servername with regexp must start with a ~
. The example would be :
server_name = ~^.*\.example\.com$;
In this case, it could be rewritten with a wildcard (supposing that we don't use a.b.....example.com, but just a.example.com)
server_name = *.example.com;
But, if the animal is to be reused somewhere in nginx config file, then you should use a regexp and capture the animal name in the $animal variable. Here is the idea. Completely untested.
server_name = ~^(?<animal>[^.]*)\.example\.com$;
....
location / {
try_files $uri $uri/ @dokuwiki;
}
location @dokuwiki {
# rewrites "doku.php/" out of the URLs if you set the userwrite setting to .htaccess in dokuwiki config page
rewrite ^/_media/(.*) /lib/exe/fetch.php?media=$1&animal=$animal last;
rewrite ^/_detail/(.*) /lib/exe/detail.php?media=$1&animal=$animal last;
rewrite ^/_export/([^/]+)/(.*) /doku.php?do=export_$1&id=$2&animal=$animal last;
rewrite ^/(.*) /doku.php?id=$1&animal=$animal&$args last;
}
EDIT NOTE:
I initially used servername
which is wrong. The correct spelling is server_name
. Forgot also to en the server_name
statement by a ;
.