apiVersion: extensions/v1beta1
kind: Ingress
metadata:
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
ingress.bluemix.net/rewrite-path: "serviceName=nginx rewrite=/"
name: nginx-ingress
namespace: 'default'
spec:
rules:
- host: www.domain.com
http:
paths:
- path: /*
backend:
serviceName: nginx
servicePort: 80
Here I have some ingress config yaml
file. When I apply it all working correctly but only when you go by path www.domain.com
, when I try to use domain.com
, it doesn't work and return me
default backend - 404
What should I do ? Add one more host to the rules:
- host: domain.com
http:
paths:
- path: /*
backend:
serviceName: nginx
servicePort: 80
Like this or I can use better solving of this problem ?
add an ingress alias annotation to the annotations
block:
nginx.ingress.kubernetes.io/server-alias: domain.com
You can set another host rule for the domain.com
. However, this is more suitable if you want different path rules for it. To use the same rules, it's better to set the server-alias
annotation:
Allows the definition of one or more aliases in the server definition of the NGINX configuration using the annotation
nginx.ingress.kubernetes.io/server-alias: "<alias 1>,<alias 2>"
. This will create a server with the same configuration, but adding new values to theserver_name
directive.
Use this:
nginx.ingress.kubernetes.io/server-alias: domain.com
Remember that you can configure the from-to-www-redirect
annotation too:
In some scenarios is required to redirect from
www.domain.com
todomain.com
or vice versa. To enable this feature use the annotationnginx.ingress.kubernetes.io/from-to-www-redirect: "true"