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

featMarcel asked:



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


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


have the same root


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 *;
    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.