Nginx: サブドメインを使用して同じサーバー上で複数の Web アプリを実行する

Nginx: サブドメインを使用して同じサーバー上で複数の Web アプリを実行する

私は をしていてUbuntu 20.04.1 LTS、 を走っていますnginx/1.18.0 (Ubuntu)

/etc/nginx/sites-available基本的に、リクエストを次の場所にルーティングしたいので、フォルダー内に 3 つの構成ファイルがあります。

  1. マイサーバー
  2. このサイトについて
  3. アイテム.myserver.com

私のmyserver.com設定ファイルは次のようになります:

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




}

私の nginx-config はimmos.myserver.com次のようになります。

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;
    }

}

私の nginx 設定はitems.myserver.com次のようになります。

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;
    }

}

すべてのサブドメインとドメインは DNS 上でサーバーの IP にルーティングされます。

開いmyserver.comて正しいページに誘導できます。

しかし、 を開くとimmos.myserver.comitems.myserver.comで実行されているアプリケーションにルーティングされますmyserver.com

これら 3 つのアプリケーションはすべて Laravel アプリケーションです。

私が何を間違っているのか、何かアドバイスはありますか?

関連情報