Report this

What is the reason for this report?

How to I support both www.abc.com and abc.com?

Posted on November 25, 2019

Hi, I recently set up my kubernetes with ingress. I am able to access my REST through www.abc.com/api for example, however, if I try to access it via abc.com/api or abc.com/ doesn’t seem to reach the server (404).

How can I enable my server to be reachable by both www.abc.com and abc.com?

Below is my ingress definition


apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: web-ingress
  annotations:
    kubernetes.io/ingress.class:  'nginx'
    nginx.ingress.kubernetes.io/from-to-www-redirect: "True"
spec:
  rules:
  - host: www.abc.com
    http:
      paths:
      - path: /
        backend:
          serviceName: abc-web-service
          servicePort: 80
      - path: /api
        backend:
          serviceName: abc-rest-service
          servicePort: 80


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.

Hello, @brancojunio

The first step will be to make sure that both abc.com and www.adc.dom DNS is pointed to your droplet/server. If that is already configured your can simply redirect www to non-www or vice versa.

Let me know if you have any questions.

Regards, Alex

Hi thank you for your reply!

I believe the domain is already set up to my droplet/server as I can access it via www.abc.com already. How would I go about redirecting any requests to “abc.com” to -> “www.abc.com” ?

Kind Regards Junio

If you’re using Nginx, you could do something like the following within your Nginx config:

server {
  ....
  server_name example.com www.example.com;
  rewrite ^ https://www.example.com$request_uri? permanent;
  ....
}

Think different and code well,

-Conrad

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.