Link any subdomain to a different path than the www-path in nginx conf-file

featMarcel asked:

Example:

http://example.com

and

http://www.example.com

are linked to the path (it’s their root)

/var/www

I want that any other subdomain (like test.example.com or 1234.example.com) is linked automatically (without defining the subdomain as server_name in a conf-file) to /var/www/pathforanysub for example:

test.example.com

and

1234.example.com

have the same root

/var/www/pathforanysub

I’m very new to nginx and it would be quite cool if someone could help me..

My answer:


You have to create a new server block, with a wildcard server_name.

server {
    server_name *.example.com;
    root /var/www/whatever;

View the full question and answer on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.