Search code examples
nginxopenshiftkubernetes-ingressnginx-ingresshaproxy-ingress

Bad redirection through ingress-controllers with custom ports on OpenShift


My scheme:

Previous traffic path:
-- 80 --> Ingress -- 80 --> Nginx -- 8123 --> Backend

I've changed the listening ports in the Nginx container to migrate from k8s to OpenShift. Now my Nginx works on port 8081 instead of 80.

Current traffic path:
-- 80 --> Ingress -- 8081 --> Nginx -- 8123 --> Backend

My nginx.conf:

server {
    listen   8081;

    server_name frontend;
    charset utf8;

    }
    location /auth {
        proxy_pass http://backend:8123;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header Cookie $http_cookie;
        proxy_pass_header Set-Cookie;
    }

***

When I open the https://<My-test-app>/auth in browser I get the redirect https://<My-test-app>:8081/auth.

I've tried to fix this problem on my k8s stand, and I've done it.

These annotations have been very usefull:

nginx.ingress.kubernetes.io/proxy-redirect-from : http://<My-test-app>:8081/
nginx.ingress.kubernetes.io/proxy-redirect-to : https://<My-test-app>/ 

But the OpenShift used an HA-Proxy ingress controller and I couldn't found any annotations like these.

Maybe someone has resolved this problem or known a better solution?


Solution

  • I've resolved this problem on an application level. Adding the line proxy_redirect http://backend:8123/ http://backend/ helped to solve this problem.

    server {
        listen   8081;
    
        server_name frontend;
        charset utf8;
    
        }
        location /auth {
            proxy_pass http://backend:8123;
            proxy_redirect http://backend:8123/ http://backend/
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header Cookie $http_cookie;
            proxy_pass_header Set-Cookie;
        }
    
    ***