Nginx: Ausführen mehrerer Webanwendungen auf demselben Server mithilfe von Subdomänen

Nginx: Ausführen mehrerer Webanwendungen auf demselben Server mithilfe von Subdomänen

Ich habe ein Ubuntu 20.04.1 LTSund ich laufe nginx/1.18.0 (Ubuntu).

Ich habe grundsätzlich drei Konfigurationsdateien in meinem Ordner, /etc/nginx/sites-availableda ich Anfragen an folgende Adresse weiterleiten möchte:

  1. myserver.com
  2. immos.myserver.com
  3. items.myserver.com

Meine myserver.comKonfigurationsdatei sieht wie folgt aus:

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




}

Die nginx-config von mir immos.myserver.comsieht wie folgt aus:

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

}

Meine Nginx-Konfiguration items.myserver.comsieht wie folgt aus:

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

}

Alle Subdomänen und die Domäne werden über das DNS zur IP meines Servers weitergeleitet.

Ich kann es öffnen myserver.comund werde zur richtigen Seite weitergeleitet.

ABER beim Öffnen immos.myserver.comwerde items.myserver.comich zu der Anwendung weitergeleitet, die darauf ausgeführt wird myserver.com.

Alle drei Anwendungen sind Laravel-Anwendungen.

Irgendwelche Vorschläge, was ich falsch mache?

verwandte Informationen