'Can't acces to AWS Kibana VPC-Based with nginx using Cognito

I use Elasticsearch VPC-based, for connect to kibana I use nginx reverse proxy. I'm followed this : https://aws.amazon.com/premiumsupport/knowledge-center/kibana-outside-vpc-nginx-elasticsearch/?nc1=h_ls.

When I try to access to https://ec2-x-x-x-x.region-x.compute.amazonaws.com (EC2 instance containts nginx ). I have a redirect to https://ec2-x-x-x-x.region-x.compute.amazonaws.com/login?response_type=code&client_id=xxxx... instead https://auth.website.com/login?response_type=code&client_id=xxxx... (auth.website.com is Cognito host)

Then I have an 502 bad gateway.

My nginx config :

server {
            listen 443;
            server_name $host;
            rewrite ^/$ https://$host/_plugin/kibana redirect;
    
            ssl_certificate           /etc/nginx/cert.crt;
            ssl_certificate_key       /etc/nginx/cert.key;
    
            ssl on;
            ssl_session_cache  builtin:1000  shared:SSL:10m;
            ssl_protocols  TLSv1 TLSv1.1 TLSv1.2;
            ssl_ciphers HIGH:!aNULL:!eNULL:!EXPORT:!CAMELLIA:!DES:!MD5:!PSK:!RC4;
            ssl_prefer_server_ciphers on;
    
            location /_plugin/kibana {
                # Forward requests to Kibana
                proxy_pass https://vpc-domain-xxxxx.region.es.amazonaws.com/_plugin/kibana;
    
                # Handle redirects to Amazon Cognito
                proxy_redirect https://auth.exmample.com https://$host;
    
                # Update cookie domain and path
                proxy_cookie_domain vpc-domain-xxxxx.region.es.amazonaws.com $host;
                proxy_cookie_path / /_plugin/kibana/;
    
                # Response buffer settings
                proxy_buffer_size 128k;
                proxy_buffers 4 256k;
                proxy_busy_buffers_size 256k;
            }
    
            location ~ \/(log|sign|error|fav|forgot|change|saml|oauth2) {
                # Forward requests to Cognito
                proxy_pass https://auth.exmample.com;
    
                # Handle redirects to Kibana
                proxy_redirect https://vpc-domain-xxxxx.region.es.amazonaws.com https://$host;
    
                # Update cookie domain
                proxy_cookie_domain auth.exmample.com $host;
            }
        }

Thank you



Solution 1:[1]

  1. Relaunch the page with browser Developer Tools enabled and "Network" tab is selected. You might able to start the investigation on the cause from here.
  2. access to your EC2 instance, then check the nginx log which located at /var/log/nginx/ directory (for linux based distribution).
  3. Check the security group of your EC2 instance.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 ShuuRi