www and without www for a folder and any other subdomain for another folder

1

I have a domain configured in nginx as follows:

server {
    listen 80 default_server;
    listen [::]:80 default_server;

    server_name   .dominio.com.br ~^(www\.)?(?<domain>.+)$;
    root /home/dominio.com.br/public;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }


    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
    }

    location ~ /\.ht {
        deny all;
    }
}

This makes any of these links work:

domain.com.br subdomain.domain.com

If I configure a DNS from another domain pointing to the IP of this my server the app also works because of this line:

server_name   .dominio.com.br ~^(www\.)?(?<domain>.+)$;

I would like to be able to link to another folder if the link is:

www.dominio.com.br domain.com.br

That is, any subdomain (less www) should go to a folder already the www subdomain and without www go to another folder.

I've tried creating a new server block {} as in the example below, but it did not work:

server {
    listen 80;
    listen [::]:80;

    server_name   dominio.com.br www.dominio.com.br;
    root /home/outra_pasta/public;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }


    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
    }

    location ~ /\.ht {
        deny all;
    }
}

How can I resolve this issue?

    
asked by anonymous 06.12.2016 / 03:34

0 answers