Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

up vote 4 down vote accepted

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

}
share|improve this answer
    
Perfect :) (Scenario 2) –  acidzombie24 Oct 31 '11 at 5:38

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.