如何将子域指向同一服务器上的另一个 "folder"?

How to point a subdomain to another "folder" on same server?

所以我在一台带有 forge 的服务器上设置了两个域,每个域都有存储库。它看起来像这样:

DomainA.com (179.x.x.x) DomainB.com (179.x.x.x)

在我的 DNS 中,我已将它们都指向同一个 ip,forge 已经处理了其他一切,而且效果很好。

服务器上有两个文件夹。 DomainA.com DomainB.com

所以现在我想在 DomainB 上创建一个子域,其中 "loads" DomainA 的代码,示例:code.domainb.com 将加载显示 domaina.com.[=13 中的内容=]

我不确定我该怎么做?到目前为止,我明白我需要更改 nginx 配置中的某些内容,希望有人能给我一些指示 :)

域b的Nginx配置:

# FORGE CONFIG (DO NOT REMOVE!)
include forge-conf/domainb.com/before/*;

server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    server_name .domainb.com;
    root /home/forge/domainb.com/public;

    # FORGE SSL (DO NOT REMOVE!)
    ssl_certificate /etc/nginx/ssl/domainb.com/471043/server.crt;
    ssl_certificate_key /etc/nginx/ssl/domainb.com/471043/server.key;

    ssl_protocols TLSv1.2;
    ssl_ciphers XXX;
    ssl_prefer_server_ciphers on;
    ssl_dhparam /etc/nginx/dhparams.pem;

    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;

    # FORGE CONFIG (DO NOT REMOVE!)
    include forge-conf/domainb.com/server/*;

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

    access_log off;
    error_log  /var/log/nginx/domainb.com-error.log error;

    error_page 404 /index.php;

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

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

# FORGE CONFIG (DO NOT REMOVE!)
include forge-conf/domainb.com/after/*;

域 A 的 Nginx 配置:

# FORGE CONFIG (DO NOT REMOVE!)
include forge-conf/domaina.com/before/*;

server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    server_name .domaina.com;
    root /home/forge/domaina.com/public;

    # FORGE SSL (DO NOT REMOVE!)
    ssl_certificate /etc/nginx/ssl/domaina.com/470443/server.crt;
    ssl_certificate_key /etc/nginx/ssl/domaina.com/470443/server.key;

    ssl_protocols TLSv1.2;
    ssl_ciphers XXX;
    ssl_prefer_server_ciphers on;
    ssl_dhparam /etc/nginx/dhparams.pem;

    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;

    # FORGE CONFIG (DO NOT REMOVE!)
    include forge-conf/domaina.com/server/*;

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

    access_log off;
    error_log  /var/log/nginx/domaina.com-error.log error;

    error_page 404 /index.php;

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

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

# FORGE CONFIG (DO NOT REMOVE!)
include forge-conf/domaina.com/after/*;

server_name 指令可以有多个值。完全匹配的 HOST 名称优先。有关详细信息,请参阅 this document

如果 code.domainb.com 使用与 .domaina.com 的服务器块相同的文档根目录,只需将其名称添加到 server_name 指令即可。

例如:

server {
    ...
    server_name .domainb.com;
    root /home/forge/domainb.com/public;
    ...
}
server {
    ...
    server_name .domaina.com code.domainb.com;
    root /home/forge/domaina.com/public;
    ...
}

有关更多信息,请参阅 this document