Nginx: executando vários aplicativos da web no mesmo servidor usando subdomínios

Nginx: executando vários aplicativos da web no mesmo servidor usando subdomínios

Estou tendo um Ubuntu 20.04.1 LTSe estou correndo nginx/1.18.0 (Ubuntu).

Basicamente, tenho três arquivos de configuração em minha pasta, /etc/nginx/sites-availablepois gostaria de encaminhar solicitações para:

  1. meuservidor.com
  2. immos.myserver.com
  3. itens.meuservidor.com

Meu myserver.comarquivo de configuração se parece com o seguinte:

server {
    server_name myserver.com www.myserver.com;
    root /var/www/main-application/public;

    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-XSS-Protection "1; mode=block";
    add_header X-Content-Type-Options "nosniff";

    index index.html index.htm index.php;

    charset utf-8;

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

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }

    error_page 404 /index.php;

    location ~ \.php$ {
        fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        include fastcgi_params;
    }

    location ~ /\.(?!well-known).* {
        deny all;
    }


    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/myserver.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/myserver.com/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot


}
server {
    if ($host = www.myserver.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


    if ($host = myserver.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


    listen 80;
    server_name myserver.com www.myserver.com nlg.myserver.com;
    return 404; # managed by Certbot




}

O nginx-config do meu immos.myserver.comé semelhante ao seguinte:

server {
    listen 80;
    server_name immos.myserver.com;
    root /var/www/immos-application/public;

    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-XSS-Protection "1; mode=block";
    add_header X-Content-Type-Options "nosniff";

    index index.html index.htm index.php;

    charset utf-8;

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

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }

    error_page 404 /index.php;

    location ~ \.php$ {
        fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        include fastcgi_params;
    }

    location ~ /\.(?!well-known).* {
        deny all;
    }

}

Minha configuração do nginx items.myserver.comé semelhante a esta:

server {
    listen 80;
    server_name items.myserver.com;
    root /var/www/items_application/public;

    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-XSS-Protection "1; mode=block";
    add_header X-Content-Type-Options "nosniff";

    index index.html index.htm index.php;

    charset utf-8;

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

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }

    error_page 404 /index.php;

    location ~ \.php$ {
        fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        include fastcgi_params;
    }

    location ~ /\.(?!well-known).* {
        deny all;
    }

}

Todos os subdomínios e o domínio são roteados no DNS para o ip do meu servidor.

Posso abrir myserver.come ser direcionado para a página correta.

MAS, ao abrir immos.myserver.com, items.myserver.comsou roteado para o aplicativo que está sendo executado myserver.com.

Todos os três aplicativos são aplicativos laravel.

Alguma sugestão do que estou fazendo de errado?

informação relacionada