与 root 站点不同的 nginx 子域

nginx subdomain with different site than root

我的站点中有以下可用配置(使用符号 link 启用):

#subdomain site
server {
    listen 443 ssl http2;
    server_name dokuwiki.[censored].org;

    root /var/www/html/dokuwiki;
    index index.php index.html;

    include /etc/nginx/templates/ssl.tmpl;
    location / {
        try_files $uri $uri/ @dokuwiki;
    }

    location @dokuwiki {
        rewrite ^/_media/(.*) /lib/exe/fetch.php?media= last;
        rewrite ^/_detail/(.*) /lib/exe/detail.php?media= last;
        rewrite ^/_export/([^/]+)/(.*) /doku.php?do=export_&id= last;
        rewrite ^/(.*) /doku.php?id=&$args last;
    }

    location ~ \.php$ {
        # Caution: be sure the php7.2-fpm.sock matches your version
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
    location ~ /(data|conf|bin|inc|vendor)/ {
      deny all;
    }
}

我想在站点根目录下有一个不同的站点:

#root site
server {
    listen 80;
    server_name [censored].org;

    root /var/www/html/site;
    index index.html;
}

根站点目前只是一个虚拟站点。当我尝试加载它时,浏览器尝试加载子域站点,但发出警告,因为 ssl 证书(为子域设置)不匹配。

显然我做错了什么,但是什么?

尝试缩减到没有 SSL 的最小配置,并确保首先适用于 2 个域:

server {
  listen 80;
  server_name example.com;
  return 200 "example.com";
}

server {
  listen 80;
  server_name 1.example.com;
  return 200 "1.example.com";
}
$ curl http://example.com/
example.com

$ curl http://1.example.com/
1.example.com

然后,将 SSL 添加到 HTTPs 端点以确保有效:

server {
  listen 443 ssl http2;
  ssl_certificate     example.com.crt;
  ssl_certificate_key example.com.key;

  server_name example.com;
  return 200 "example.com";
}
$ curl https://example.com/
example.com