So I have an Nuxt app running on DO. Currently only the ‘naked’ domain works(so without www) and when I visit the www. version it doesn’t work.
So what I have tried is adding a CNAME-record - Hostname www.domain.com - and as value the naked domain(e.g. ‘domain.com’). Now when I try to visit the www. version I get the following Cloudfare error:
I tried following this article: https://www.digitalocean.com/community/tutorials/how-to-redirect-www-to-non-www-with-nginx-on-ubuntu-14-04
But I can’t find any nginx or apache folders in the /etc/ folder in the console.
So how would I go about doing this?
Thanks in advance!
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
Enter your email to get $200 in credit for your first 60 days with DigitalOcean.
New accounts only. By submitting your email you agree to our Privacy Policy.
Hi there,
Redirecting from
www
to a non-www domain (or vice-versa) usually involves two main steps:www
and non-www
domain names resolve to the correct IP address.Based on your description, it appears you have a DNS resolution issue, possibly in addition to not having a server-side redirect set up.
Here are a few things that you should check:
1. Check DNS Settings:
First, ensure the DNS settings are correct:
Your
A
record should be set fordomain.com
pointing to the DigitalOcean droplet’s IP.Your
CNAME
record should have thewww
version pointing todomain.com
. The settings usually look like:CNAME
www
domain.com
Note: If you’re using Cloudflare, make sure both records (
A
fordomain.com
andCNAME
forwww
) are proxied (orange cloud icon) or set to DNS-only (grey cloud icon) based on your preference.2. Server-Side Redirect:
If you cannot find the Nginx or Apache configurations, it’s possible your application is served by a different server, or perhaps it’s running in a Docker container, or the DigitalOcean App Platform.
However, since you mentioned it’s a Nuxt app, you might be using Nuxt’s built-in server. In this case, you can handle redirects within your Nuxt configuration.
Nuxt Redirect: In
nuxt.config.js
, you can set up a redirect like this:This middleware checks if the incoming request uses the
www
subdomain and, if so, redirects it to the non-www version.3. Check Propagation:
After making DNS changes, it might take some time for the changes to propagate. Use tools like DNS Checker to ensure your domain’s DNS is correctly updated worldwide.
Let me know how it goes!
Best,
Bobby