如何在www子域上的nginx上托管2个虚拟主机



我是这一切的新手,已经努力了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域的信息,或者是否有问题。

提前非常感谢!:-)

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

最新更新