简体   繁体   中英

How to host 2 virtual hosts on nginx on www subdomains?

I am new to all this and trying hard already for 4 days without any big success. Maybe it's just a small thing and hopefully you can help me! Was not able to find an answer here so far (at least nothing worked out until now):

I have a domain, say example.com registered. I also added a subdomain test.example.com and added it as a CNAME to example.com.

Then I installed nginx and set it up following th tutorial on https://www.digitalocean.com/community/tutorials/how-to-set-up-nginx-server-blocks-virtual-hosts-on-ubuntu-14-04-lts with the minor change that I have both servers in one config file by now. In short, it looks like this:

in 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 works fine and shows me "welcome to example.com" in broswer tab and some text that example.com server is running as expected (defined index.html by me as in the example).

BUT: If I go to test.example.com it shows me in the tab "welcome to example.com" either although it should be "welcome to **test.**example.com" and there is no html page at all shown to me. it's just a blank page.

Can someone help me? I don't know, if I already got the stuff with the cname domain or whether there might be something wrong.

Thank you very muh in advance!:-)

I was able to solve my problem. It was not on the server but a wrong setting in my domain provider. I don't have to forward my domain but just set it in the nameservers instead pointing to the ip!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM