尝试在同一个端口设置域和子域。 (NGINX)

Trying to set up domain and subdomain in the same port. (NGINX)

我正在尝试使用 Nginx 运行 同一端口中的域和子域,但还没有成功。

我有一个名为 www.just4bettors.mobi 的域,用于移动页面,子域必须命名为 www.desktop.just4bettors.mobi,这显然是用于桌面站点的。

如果您输入 www.just4bettors.mobi,一切正常,您会到达该页面,但如果您输入 www.desktop.just4bettors.mobi,您会得到 This web page is not available。这是我到目前为止的服务器块

server {
        large_client_header_buffers 1 1K;

        listen       80;
        server_name  ~^(?<subdomain>[^.]*)\.?just4bettors.mobi$ just4bettors.mobi;
        root   /home/c0pt/capilleira/capilleiraclickandgamblemobile/www;

        location / {
            if ($subdomain) {
               root /home/c0pt/capilleira/capilleiraclickandgambleweb/dist;
            }
            if ($host = "just4bettors.mobi") {
                root /home/c0pt/capilleira/capilleiraclickandgamblemobile/www;
            }
            index  index.html index.htm;
            ...
        }
}

一旦我尝试访问 desktop.just4bettors.mobi,控制台 returns 这个 GET http://desktop.just4bettors.mobi/ net::ERR_NAME_NOT_RESOLVED

你知道根在这里是不同的,移动和网络生活在不同的地方。

所以,我在这里缺少什么?

我管理过使用了数百万个不同域的 Nginx 配置。尝试在一个 server{} 块指令中工作非常复杂。这是我会做的:

server {
    large_client_header_buffers 1 1K;
    listen 80;

    server_name www.just4bettors.mobi;
    root /home/c0pt/capilleira/capilleiraclickandgamblemobile/www;

    location / {
        ...
    }
}

server {
    large_client_header_buffers 1 1K;
    listen 80;

    server_name www.desktop.just4bettors.mob;
    root /home/c0pt/capilleira/capilleiraclickandgambleweb/dist;

    location / {
        ...
    }
}

您可以在此处阅读更多相关信息:http://wiki.nginx.org/Pitfalls#Server_Name