使用 Nginx 创建子域时出错

Error on creating sub domains with Nginx

这是我第一次使用 Nginx,我正在尝试创建一个子域,但是在浏览器中输入子域后,出现错误 This web page is not available :( ,所以我是来求你帮助我的,拜托

我有一种手机配置是

server {
    large_client_header_buffers 1 1K;

    listen       80;
    server_name  www.the-thing.mobi  the-thing.mobi;
    root   /home/c0pt/things/thingsMobile/www;

    location / {
     index index.html index.htm
     ...
    }
 }

另一个用于网络,这是一个不工作

server {
    listen       80;
    server_name  www.desktop.the-thing.mobi  desktop.the-thing.mobi;
    root   /home/c0pt/things/thingsWebApp/dist;

    location / {
     index index.html index.htm
     ...
    }
 }

如果我输入 www.the-thing.mobi 这是移动的子域,一切正常,但如果我输入 www.desktop.the-thing.mobi,则错误消息 This web page is not available :(出现。

那么,我做错了什么?

试试下面的配置

server {
    large_client_header_buffers 1 1K;

    listen 80;
    server_name  "~^(?<subdomain>[^.]*)\.?the-thing.mobi$"  the-thing.mobi www.the-thing.mobi;


    location / {
     if($subdomain){
      root /home/c0pt/things/thingsWebApp/dist;  
     }
     if ($host = 'the-thing.mobi'|$host = 'www.the-thing.mobi') {
     root /home/c0pt/things/thingsMobile/www;  
     }
     index index.html index.htm
     ...
    }
 }