Nginx 404 error for Cname records

Hey guys I had not added Cname record during droplet creation.(there I just added A name record)

After two moths, I realised my site should also open with www version. ( If somebody try to visit my url with www version)

That’s I just added Cname record on droplet>networking>> domain.

But when I try to visit my site with www. it is showing Nginx 404 error - Is there any server block configuration.

  • Add that in current DNS manager which related NS you are using.
    CNAME - www - example.com

Go to /etc/ngnix/sites-available/
Edit relevant server block file

server {
listen 80;
root /var/www/html;
index index.php index.html index.htm;
server_name example.com www.example.com;
...

Once done, reload NGINX

nginx -t
service nginx reload

Any additional queries? Please feel free to ask.

Alternative solution: Add that www in CF proxy mode, keep flexible and set page rule for redirect all www to non-www.

Here is my setting in digital ocean pannel :arrow_double_up:

Screenshot_26

:arrow_double_up: server block setting

:arrow_double_up: Https block setting by let’s encrypt

Still getting 404 not found

At my end, it’s working fine. Can you double check in other browser?

Yaa it’s working in opera browser.

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.