Cannot redirect to Keycloak login page on Nginx deployed Angular app

Discussão em 'Angular' iniciado por DoubleL3991, Dezembro 17, 2024.

  1. DoubleL3991

    DoubleL3991 Guest

    I need to deploy an Angular app to an Nginx server on an Amazon EC2 machine. The app uses keycloak-js and keycloak-angular to interface with a Keycloak server hosted on the same EC2 machine.

    I built the app with ng build and transfered the files to the machine. This is how I then edited the nginx.conf file:

    Added the following lines to http section to enable HTTPS/SSL (I am currently using a self-signed certificate):

    ssl_certificate /root/certs/MyCertificate.crt;
    ssl_certificate_key /root/certs/MyKey.key;
    ssl_ciphers EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH;
    ssl_protocols TLSv1.1 TLSv1.2;


    Added this server block to rewrite all HTTP URIs to HTTPS:

    server {
    listen 80;
    server_name localhost;
    return 301 https://localhost$request_uri;
    }


    Added this server block to host the app on HTTPS:

    server {
    listen 443 ssl default_server;
    listen [::]:443 ssl default_server;
    server_name localhost;
    root /var/srv/mysite;
    index index.html;

    location / {
    try_files $uri $uri/ =404;
    }
    }


    But when I try to open the app on my browser it doesn't redirect to the Keycloak login page, and after some time the console gives me this error: "Timeout when waiting for 3rd party check iframe message".

    This is the configuration I supplied to keycloak-js through the factory function initializeKeycloak:

    function initializeKeycloak(keycloak: KeycloakService) {
    return () =>
    keycloak.init({
    config: {
    url: "http://localhost:8080",
    realm: "test",
    clientId: "test-client",
    },
    loadUserProfileAtStartUp: true,
    initOptions: {
    checkLoginIframe: false,
    onLoad: 'check-sso',
    silentCheckSsoRedirectUri:
    window.location.origin + '/silent-check-sso.html'
    },
    enableBearerInterceptor: true
    });
    }


    I thought this could be a header handling problem, so I also tried adding these lines to the location / subsection:

    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;


    But nothing changed, still the same error.

    Everything works locally (if I am testing on my machine, not EC2). Is there something I forgot? Or something I am doing wrong?

    Continue reading...

Compartilhe esta Página