【问题标题】:How to host 2 virtual hosts on nginx on www subdomains?如何在 www 子域的 nginx 上托管 2 个虚拟主机?
【发布时间】:2015-11-24 22:14:41
【问题描述】:

我对这一切都很陌生,并且已经努力了 4 天,但没有取得任何重大成功。也许这只是一件小事,希望你能帮助我!到目前为止无法在这里找到答案(至少到目前为止还没有解决):

我有一个域,比如注册了 example.com。我还添加了一个子域 test.example.com 并将其作为 CNAME 添加到 example.com。

然后我安装了 nginx 并按照https://www.digitalocean.com/community/tutorials/how-to-set-up-nginx-server-blocks-virtual-hosts-on-ubuntu-14-04-lts 上的教程进行了设置,但我现在将两台服务器放在一个配置文件中进行了微小的更改。简而言之,它看起来像这样:

在 etc/nginx/sites-enabled/example.com 中

server {
    listen 80;


    root /var/www/example.com/html;
    index index.html index.htm;

    server_name example.com www.example.com;

    location / {
        try_files $uri $uri/ =404;
    }
}


server {
    listen 80;

    root /var/www/test.example.com/html;
    index index.html index.htm;

    server_name test.example.com www.test.example.com;

    location / {
        try_files $uri $uri/ =404;
    }
}

example.com 工作正常,并在 broswer 选项卡中向我显示“欢迎来到 example.com”,以及 example.com 服务器按预期运行的一些文本(如示例中我定义的 index.html)。

但是:如果我去 test.example.com,它会在标签“欢迎来到 example.com”中显示我,尽管它应该是“欢迎来到 **test.**example.com”并且没有 html页面完全显示给我。这只是一个空白页。

有人可以帮助我吗?我不知道,如果我已经得到了 cname 域的东西,或者是否有问题。

非常感谢您!:-)

【问题讨论】:

  • 我刚刚注意到 example.com 上的 broswer 选项卡向我显示“Apache Ubuntu 默认页面”,但页面是成功消息。在切换到 nginx 之前,我已经安装了 Apache。卸载 Apache 时可能出现问题。会去看看的!

标签: nginx webserver subdomain cname


【解决方案1】:

我能够解决我的问题。它不在服务器上,而是我的域提供商中的错误设置。我不必转发我的域,只需将其设置在名称服务器中,而不是指向 ip!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-02-09
    • 2012-12-24
    • 2014-12-26
    • 1970-01-01
    • 2016-10-26
    • 2012-08-18
    • 1970-01-01
    • 2021-05-09
    相关资源
    最近更新 更多