Base solution for your next web application
Ends in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

Chat feature is not working on Angular app deployed as a container in Nginx #10199


User avatar
0
Hamzah.Alfraydi created

Prerequisites

  • What is your product version? v10.2.0
  • we are using .net core framework with Angular

we are using the ASP .Net Zero hosted on Docker Container on Nginx we managed the cors policy and the site works just fine ,However the chat feature and signalR didnot work at all with the following error:

Access to fetch at 'https://xxxxxxxxxxxxx/signalr-chat/negotiate?enc_auth_token=xxxxxxxxxxxxx&negotiateVersion=1' from origin 'https://xxxxxxxxxxxxx' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: The value of the 'Access-Control-Allow-Credentials' header in the response is '' which must be 'true' when the request's credentials mode is 'include'.

we tried to use the wild card , in the cors policy like "*.xxxxxxxx.com" and the full URL but all of them didnot work

nginx.config server { server_name frontendApp.xxxx ; include /etc/nginx/conf.d/config/config.conf; location / { proxy_pass http://API.xxxxxxxxxx; proxy_http_version 1.1; proxy_set_header Host $host; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection $http_connection; proxy_cache_bypass $http_upgrade; proxy_set_header Connection keep-alive; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Host $server_name; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header Upgrade $http_upgrade; proxy_cache_bypass $http_upgrade; proxy_pass_request_headers on; } location /signalr { proxy_pass http://API.xxxxxxxxxx; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; proxy_set_header Host $host; proxy_cache_bypass $http_upgrade; } location /signalr-chat { proxy_pass http://API.xxxxxxxxx; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; proxy_set_header Host $host; proxy_cache_bypass $http_upgrade; } include /etc/nginx/conf.d/ssl/ibtik.net-ssl.conf; add_header 'Access-Control-Allow-Origin' 'https://UI.xxxxxx' always; add_header 'Access-Control-Allow-Headers' ''; add_header 'Access-Control-Allow-Methods' ''; }


2 Answer(s)
  • User Avatar
    0
    [email protected] created

    Same issue , found any help?

  • User Avatar
    0
    slamj2 created

    Put this in your main nginx.conf file under the http section:

    map $http\_connection $connection\_upgrade {
    "\~\*Upgrade" $http\_connection;
    default keep-alive;
    }
    

    Then, in your site conf file use this for your hub location(s):

    location /signalr-chat {
        proxy_pass http://x.x.x.x:port;
        
        # Configuration for WebSockets.$http_upgrade, $connection_upgrade is mapped in main server conf file. 
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection $connection_upgrade; 
        proxy_cache off;
    
        #   Configuration for ServerSentEvents
        proxy_buffering off;
    
        # Configuration for LongPolling or if your KeepAliveInterval is longer than 60 seconds
        proxy_read_timeout 100s;
    
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;		
        proxy_set_header   Accept-Language $http_accept_language; # Optional
    }
    
    location /signalr {
        proxy_pass         http://x.x.x.x:port;
    
        # Configuration for WebSockets.$http_upgrade, $connection_upgrade is mapped in main server conf file. 
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection $connection_upgrade; 
        proxy_cache off;
    
        #   Configuration for ServerSentEvents
        proxy_buffering off;
    
        # Configuration for LongPolling or if your KeepAliveInterval is longer than 60 seconds
        proxy_read_timeout 100s;
    
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;		
        proxy_set_header   Accept-Language $http_accept_language; # Optional
    }
    

    The CORS error message can be a bit of a red herring if the proxy config is not quite right. Note that this is direct from Microsoft's config site on Nginx -> https://docs.microsoft.com/en-us/aspnet/core/signalr/scale?view=aspnetcore-5.0

    Cheers.