nginx how to create server block for sub domain?

I have a domain http://blabla.com which points to an ip address 103.35.123.4.12. I then have a sub domain http://mew.blabla.com which points to the same ip address. Using nginx how can I differentiate between the two domain names? I currently have the following:

server {
    listen 80;
    server_name blabla.com;

    location ^~ / {

    }
}

server {
    listen 80
    server_name mew.blabla.com;

    location ^~ /mew/ {

    }
}

Currently both blabla.com and mew.blabla.com redirect to the root directory, how can I create a server block for the sub domain?

EDIT: Currently mew.blabla.com is not being recognised as the subdomain, is it a problem with both domains sharing the same IP?


Solution 1:

What you probably want is:

server {
    listen 80;
    server_name blabla.com;
    root /var/www/blabla.com;
    location / {
        try_files $uri $uri/ =404;
    }
}

server {
    listen 80;
    server_name mew.blabla.com;
    root /var/www/mew.blabla.com;
    location / {
        try_files $uri $uri/ =404;
    }
}

So, then content for mew.blabla.com will be served from the path /var/www/mew.blabla.com, while content for blabla.com will be served from the path /var/www/blabla.com.