不同的 DNS 指向同一台服务器但访问不同的目录

不同的 DNS 指向同一台服务器但访问不同的目录

问题

当我输入domainB.comURL 时,它会强制重定向,或者在显示 URL 时domainA.com显示内容domainAdomainB.com

预期结果

我希望domainA.comdomainB.com分别显示自己的内容,这意味着

  • domainA.com显示内容var/www/DomainA

  • domainB.com显示内容var/www/DomainB

Nginx 配置

# domainA.com
server {
    listen 80;

    server_name domainA.com;

    if ($host = "www.domainA.com") {
            return 301 https://www.domainA.com$request_uri;
    }
}

server {
    listen 443;
    listen [::]:443;

    server_name domainA.com www.domainA.com;

    root /var/www/resume;

    ssl on;
    ssl_certificate /etc/nginx/ssl/domainA.com/domainA.com.crt;
    ssl_certificate_key /etc/nginx/ssl/domainA.com/domainA.com.key;

    index index.php;

    location / {
        try_files $uri $uri/ /index.php?$args =404;
    }

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
}
# domainB.com

server {
    listen 80;
    server_name subdomain.domainB.com;

    if ($host = subdomain.domainB.com) {
        return 301 https://$host$request_uri;
    }

    return 404;
}

server {
    listen 443 ssl;

    server_name subdomain.domainB.com;

    return 301 https://$host$request_uri;

    ssl_certificate /etc/letsencrypt/live/subdomain.domainB.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/subdomain.domainB.com/privkey.pem;
    include /etc/letsencrypt/options-ssl-nginx.conf;
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;

    root /var/www/simple-crm/ui/dist;

    index index.html index.htm index.nginx-debian.html;

    location / {
        # First attempt to serve request as file, then
        # as directory, then fall back to displaying a 404.
        auth_basic "Cady's Personal Area";
        auth_basic_user_file /etc/nginx/.htpasswd;
        root /var/www/simple-crm/ui/dist;
        try_files $uri $uri/ =404;
    }

}

我想实现什么

我希望网站根据我输入的 URL 显示正确的内容。

相关内容