1

I would like all subdomains to be mapped to a particular folder and 404 if nothing exist. So if i have a wordpress install i would like nginx to see ANYTHING.mysite.com and attempt to host files from /var/log/mysite/subdomaindir/ANYTHING

How might i do that?

1 Answers1

3

I am not entirely certain which scenario, of those below, you are looking for, but both are easy to accomplish. Specifying '404 if nothing exists' shouldn't be necessary as that is the default behaviour of nginx anyway (although, you can customize the error page if you want).

Scenario 1: redirect all subdomains to the SAME folder:

server {
    server_name *.mysite.com;
    root /var/www/mysite/subdomaindir/;

    ...your other blocks/directives

}

Scenario 2: redirect all subdomains, each to their own folder:

server {
    server_name ~^(?<sub>.+)\.mysite\.com$;
    root /var/www/mysite/subdomaindir/$sub;

    ...your other blocks/directives

}
cyberx86
  • 20,805
  • 1
  • 62
  • 81