REF: 502 Bad Gateway Error after Registration

2,369 views
Skip to first unread message

Teddy Nyambe

unread,
Aug 26, 2021, 10:39:09 AM8/26/21
to Keycloak User
I am using docker for my keycloak running behind nginx also docker container. My configuration is as follows:

version: "3.8"
services:
        nginx-web:
                image: nginx:1.21.1-alpine
                restart: always
                volumes:
                        - ./nginx/default.conf:/etc/nginx/conf.d/default.conf
                        - ./ssl:/etc/nginx/ssl
                ports:
                        - "80:80"
                        - "443:443"

        mysql_db:
                image: mysql:8.0.26
                restart: always
                environment:
                        MYSQL_DATABASE: keycloak
                        MYSQL_ROOT_PASSWORD: xxx
                        MYSQL_USER: keycloak
                        MYSQL_PASSWORD: xxx
                command: --init-file /data/application/init.sql
                volumes:
                        - keycloak_db_volume:/var/lib/mysql
                        - ./db/init.sql:/data/application/init.sql

        keycloak:
               image: jboss/keycloak:15.0.1
               depends_on:
                       - mysql_db
               environment:
                       DB_VENDOR: MYSQL
                       DB_ADDR: mysql_db
                       DB_DATABASE: keycloak
                       DB_USER: root
                       DB_PASSWORD: xxxx
                       KEYCLOAK_USER: admin
                       KEYCLOAK_PASSWORD: xxx
                       DB_PORT: 3306
                       DB_USER: root
                       DB_PASSWORD: xxx
                       PROXY_ADDRESS_FORWARDING: "true"
volumes:
        keycloak_db_volume:

Its working fine I am able to login via my flutter client and postman. However, when i tried to test user registration using the form i got the error:

502 Bad Gateway nginx/1.21.1

What have i missed out?

Teddy L.

Peter Flintholm

unread,
Aug 26, 2021, 10:51:11 AM8/26/21
to Teddy Nyambe, Keycloak User

That looks like a problem in your nginx config. Could you post that as well ?

 

-Peter

--
You received this message because you are subscribed to the Google Groups "Keycloak User" group.
To unsubscribe from this group and stop receiving emails from it, send an email to keycloak-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/keycloak-user/aab7a1b3-9a88-49c6-bf7d-7e409b8dca73n%40googlegroups.com.

Teddy Nyambe

unread,
Aug 26, 2021, 11:00:52 AM8/26/21
to Keycloak User
The nginx config is as follows:

server {
    listen 80;
    listen [::]:80;
    server_name apps.infinityworx.co;
    return 301 https://apps.infinityworx.co$request_uri;
}

server {
  listen 443 ssl;
  ssl     on;
  ssl_certificate /etc/nginx/ssl/certificate-apps.crt;
  ssl_certificate_key     /etc/nginx/ssl/private-apps.key;
  ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
  ssl_prefer_server_ciphers on;
  ssl_ciphers AES256+EECDH:AES256+EDH:!aNULL;
  server_name apps.infinityworx.co;
  #location / {
    # This would be the directory where your React app's static files are stored at
  #  root /usr/share/nginx/html;
  #  try_files $uri /index.html;
  #}

  location /auth {
    #proxy_set_header X-Real-IP $remote_addr;
    #proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-For $host;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection ‘upgrade’;
    #proxy_set_header X-NginX-Proxy true;
    proxy_pass http://keycloak:8080/auth;
    #proxy_ssl_session_reuse off;
    proxy_set_header Host $host;
    #proxy_cache_bypass $http_upgrade;
    #proxy_redirect off;
  }
}

Yah noticed this error also in my nginx docker:

nginx-web_1  | 2021/08/26 14:29:15 [error] 31#31: *3277 upstream sent too big header while reading response header from upstream, client: 102.219.103.21, server: apps.infinityworx.co, request: "POST /auth/realms/farmapp/login-actions/registration?session_code=GJocNe5gLlhjvN8pV6PoE83r05FP2IHhNuHQy8xACUA&execution=fffaf6b6-41bf-4228-b7fe-09ba7d7a3ef8&client_id=farm-app-flutter&tab_id=uhdHdFA9EEU HTTP/1.1", upstream: "http://172.29.0.2:8080/auth/realms/farmapp/login-actions/registration?session_code=GJocNe5gLlhjvN8pV6PoE83r05FP2IHhNuHQy8xACUA&execution=fffaf6b6-41bf-4228-b7fe-09ba7d7a3ef8&client_id=farm-app-flutter&tab_id=uhdHdFA9EEU", host: "apps.infinityworx.co"
nginx-web_1  | 102.219.103.21 - - [26/Aug/2021:14:29:15 +0000] "POST /auth/realms/farmapp/login-actions/registration?session_code=GJocNe5gLlhjvN8pV6PoE83r05FP2IHhNuHQy8xACUA&execution=fffaf6b6-41bf-4228-b7fe-09ba7d7a3ef8&client_id=farm-app-flutter&tab_id=uhdHdFA9EEU HTTP/1.1" 502 157 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:91.0) Gecko/20100101 Firefox/91.0" "

Teddy Nyambe

unread,
Aug 26, 2021, 11:12:42 AM8/26/21
to Keycloak User
Ok managed to resolve the problem. It was as a result of the buffers or nginx, resolved it by increasing the buffers in the nginx configuration file as follows:

proxy_buffer_size 128k;
proxy_buffers 4 256k;
proxy_busy_buffers_size 256k;


Thanks for your help.

Teddy L.
Reply all
Reply to author
Forward
0 new messages