Search code examples
.netwebsocketblazoropenidnginx-reverse-proxy

.NET 6 | C# | Blazor Server websocket connection failed after openid auth


I have Blazor Server app, which is hosted on our VPS in docker, behind nginx reverse proxy. If I go to the web, it's okay and all is clear and working. enter image description here But if I login via openid (keycloak), after redirecting back with all cookies and JWT's - app cannot connect to websocket. enter image description here

I tried all variety of nginx configuration, but I don't think it's on nginx side at this point. Connection without authorization is ok. Maybe it's some kind of configuration which I'm missing?

I appreciate any help. Thank you.

EDIT: Solved thanks to @thrsn

Add

large_client_header_buffers 4 32k; 

to the nginx config (at least I had to) between http {..}


Solution

  • If you haven't found the solution for this or you are someone looking for the answer as I was:

    I have just been in the same situation as you (.NET 6 Blazor with Keycloak behind nginx) and I figured out that the issue lies in the size of the cookies generated from Blazor+Keycloak. They exceed the normal 8192 bytes of large_client_header_buffers: http://nginx.org/en/docs/http/ngx_http_core_module.html#large_client_header_buffers

    I increased the limit to:

    large_client_header_buffers 4 32k;
    

    And this solved my issue!

    NB the override should be inside the server { ... } nginx tag.