Search code examples
kubernetesnginxistionginx-config

nginx istio url not resolved and return 426 status code


i have a service that name is image-api. the image-api is accessible in pod but nginx return 426 status code

after running this command return the expected data

curl image-api.gateways.svc.cluster.local:8000

but nginx return 426 status code.

if replace the native url of image-api by istio url then nginx return 200 status code.

the /etc/nginx.nginx.conf

worker_processes 8;

events {
    worker_connections 1024;
}

http {
    resolver kube-dns.kube-system valid=10s;

    server_tokens off;

    server {
        listen 8080;

        location ~ ^/(\w+) {
            # ISTIO URL
        proxy_pass http://image-api.gateways.svc.cluster.local:8000$request_uri;
            # MAIN URL
#       proxy_pass http://image-api.main.svc.cluster.local:8000$request_uri;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }
    }
}

Solution

  • Thanks to @fariya-rahmat. his answer helps me to find the answer.

    add proxy_http_version 1.1 is necessary but it's not enough.

    the main problem is proxy_set_header Host $host; the envoy proxy detects the target service by hostname and it is wrong. if delete proxy_set_header the hostname is set automatically based on proxy_pass.