Subdomains not working on nginx

I decided to give a try to nginx, however it seems I am stuck at the really beggining. I have a server running Debian and I am trying to configure nginx with 1 domain + 2 subdomains. When I access the main domain it shows what it's supposed to. When I access the first subdomain it access to the correct folder, but when I access to the second subdomain it shows the main domain instead. Here is what I modified so far:

sites-available (main domain) works ok

server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/domain.com/public_html/;
index index.php index.html index.htm index.nginx-debian.html;
server_name www.domain.com domain.com;
location / {
    try_files $uri $uri/ =404;
}
}

sites-available (first subdomain) works ok

server{
listen 80;
listen [::]:80;
root /var/www/sub1.domain.com;
index index.php index.html index.htm index.nginx-debian.html;
server_name sub1.domain.com;
location / {
    try_files $uri $uri/ =404;
}
}

sites available (second subdomain) redirects to main domain

server{
listen 80;
listen [::]:80;
root /var/www/sub2.domain.com;
index index.php index.html index.htm index.nginx-debian.html;
server_name sub2.domain.com;
location / {
try_files $uri $uri/ =404;
}
}

I created a symlink of this files to sites-enabled and I also added them to /etc/hosts

Server IP            www.domain.com               domain.com
Server IP            sub1.domain.com
Server IP            sub2.domain.com

The domain and both subdomains have an A record pointing to the server IP. I restarted nginx and the server several times, cleared the cookies and cache on all browsers, tried from different PC... I can't see what is wrong in the configuration of the second subdomain.

Any help will be appreciated!!

ED: here are some logs:

ERROR.LOG

2015/11/17 22:41:16 [notice] 10184#0: signal process started
2015/11/17 22:56:46 [notice] 10891#0: signal process started
2015/11/17 23:06:37 [notice] 11332#0: signal process started

It is basically full of those ones.

ACCESS.LOG

94.23.253.89 - - [17/Nov/2015:23:13:24 +0100] "GET / HTTP/1.1" 200 18 "-" "curl/7.38.0"
94.23.253.89 - - [17/Nov/2015:23:14:30 +0100] "GET / HTTP/1.1" 200 18 "-" "lwp-request/6.03 libwww-perl/6.08"
94.23.253.89 - - [17/Nov/2015:23:14:48 +0100] "GET / HTTP/1.1" 200 18 "-" "lwp-request/6.03 libwww-perl/6.08"
94.23.253.89 - - [17/Nov/2015:23:15:35 +0100] "GET / HTTP/1.1" 200 18 "-" "lwp-request/6.03 libwww-perl/6.08"
94.23.253.89 - - [17/Nov/2015:23:15:52 +0100] "GET / HTTP/1.1" 200 18 "-" "lwp-request/6.03 libwww-perl/6.08"
94.23.253.89 - - [17/Nov/2015:23:15:58 +0100] "GET / HTTP/1.1" 200 18 "-" "lwp-request/6.03 libwww-perl/6.08"
94.23.253.89 - - [17/Nov/2015:23:16:05 +0100] "GET / HTTP/1.1" 200 18 "-" "lwp-request/6.03 libwww-perl/6.08"

Solution 1:

server {
        set $docroot "/var/www/domain.com/public_html/";
        listen 80 default_server;
        server_name www.domain.com domain.com;
        root $docroot;
        try_files $uri $uri/ /index.php?$args;
        index index.php index.html index.htm;
}

server {
        set $docroot "/var/www/sub1domain.com/public_html/";
        listen 80;
        server_name www.sub1.domain.com sub1.domain.com;
        root $docroot;
        try_files $uri $uri/ /index.php?$args;
        index index.php index.html index.htm;
}

server {
        set $docroot "/var/www/sub2.domain.com/public_html/";
        listen 80;
        server_name www.sub2.domain.com sub2.domain.com;
        root $docroot;
        try_files $uri $uri/ /index.php?$args;
        index index.php index.html index.htm;
}

Make sure that in the sites enabled they are sim-links to the sites-available directory. You can put the above into one file or you can put each into a septate file inside the sites-available directory.

To test your config with nginx use "nginx -t" this will show you if your config is correct without affecting the server.