如何在nginx中配置多个子域?

How to configure multiple sub-domain in nginx?

我想将子域添加到我在 nginx 上托管的网站。为此,我已将子域名添加到 nginx.conf 文件中。但是每当我尝试访问本地主机之外的子域时,它都会将我重定向到 http://id.domain-error.com/noresult.php

这是我的 nginx.conf 文件:

http {

    server {
    listen 80; # Incoming port for Nginx
    server_name www.example.com example.com;
    index index.html index.htm;
    location / {
           root /usr/share/nginx/example;
           try_files $uri $uri/ =404;
           }
    }
    server {
    listen 80; # Incoming port for Nginx
    server_name hello.example.com;
    index index.html index.htm;
    location / {
           root /usr/share/nginx/some_other_example;
           try_files $uri $uri/ =404;
           }
    }
  }

谁能告诉我我在这里遗漏了什么?

正如@Alexey 所指出的,我需要在 DNS 配置中添加子域。我只是添加了一个通配符 *.example.com 并且它开始工作了。