www not working

January 21, 2019 505 views
Networking

I’m new to all this so sorry if this is a silly question.

If I visit my site without the www it works fine, but with the www I get an error “server IP address could not be found.”

I followed the tutorials and my file: /etc/nginx/sites-available/animalrescue.co.uk looks like this:

server {
listen 80;
listen [::]:80;

    root /var/www/animalrescue.co.uk/html;
    index index.html index.htm index.nginx-debian.html;

    server_name animalrescue.co.uk www.animalrescue.co.uk;

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

}

Am I missing something?

thanks

5 Answers

Yup, I think you’re missing the DNS entry…

Please go back to you Domain Registrar or Domain Management and check if you have a CNAME www (value) that points to animalrescue.co.uk. (don’t miss the . [dot] after uk, that’s important).

And btw… allow a few minutes for DNS propagation, won’t work immediately.

Hehe… I see that you have that entry:

;; ANSWER SECTION:
www.animalrescue.co.uk. 21599 IN CNAME animalrescue.co.uk.

If the problem still persists please clear your browser cache, it works for me both versions, www and no-www.

PS: Do a redirect from www to non-www or the other way around, stick with just one domain “version” for your website as Google will see this as duplicate content and you won’t get there any time soon.

Just in case, if you want to redirect non www to www :

server {
listen 80;
servername yoursite.com;
return 301 http://www.yoursite.com$request
uri;
}

Hope that helped :) !

Have another answer? Share your knowledge.