NodeBalancer: why do I get a 404?
Hello!
I have followed this tutorial https://www.linode.com/docs/guides/how-to-deploy-nginx-ingress-on-linode-kubernetes-engine/
Let's say my website is example.com
example.com works just fine but www.example.com is not working: I get a 404.
I have multiple A records linked to the IP address of my NodeBalancer:
- example.com
- www
In the terminal I did ping example.com and www.example.com and both of them are linked to the IP address of my NodeBalancer which is good.
It does not seem to be a DNS issue. It is more likely a web server (Nginx) issue. What do you think? Can anyone help me? :)
Thank you
2 Replies
Does nginx on your backend Linode(s) answer for both example.com and www.example.com?
I.e. the server block has both www.example.com and example.com in the server_name directive?
Hello Andysh
In my Ingress file, the host was 'example.com'.
I added an annotation in my ingress file:
nginx.ingress.kubernetes.io/server-alias: 'www.example.com'
Another solution is to redirect www.example.com requests to example.com by using this annotation:
nginx.ingress.kubernetes.io/from-to-www-redirect: "true"
Both are working!
Thank you