Hi there,
I have deployed a Unity WebGL build on a Linux Ubuntu server. My game is a turn-based multiplayer game, and I am using Unity Services to handle networking. The network topology follows a client-server model, and I’m using the Protocol Type as Relay Unity Service in the Unity Transport Script and the “Use Web Sockets” bool is checked to true.
Initially, the client was connecting to the server through the Matchmaker service. However, once I published the WebGL build using the HTTPS protocol, the client was no longer able to connect via Matchmaker.
To resolve this, I switched to using Unity Relay in combination with the Lobby service to establish the connection between the client and server as discussed here, which worked correctly in my local environment.
However, after deploying the build to the Ubuntu server and testing the released version of the WebGL game, I encountered the following error:
BuildDeploy.framework.js.gz:9
Refused to connect to 'wss://6799269696119042597-asia-northeast1.relay.cloud.unity3d.com:37011/' because it violates the following Content Security Policy directive: "default-src https: data: 'unsafe-inline' 'unsafe-eval' 'self'". Note that 'connect-src' was not explicitly set, so 'default-src' is used as a fallback.
I have tried different solutions for that Like adding headers via Nginx:
add_header Content-Security-Policy "default-src 'self' https: data: 'unsafe-inline' 'unsafe-eval'; connect-src 'self' https: wss://*.relay.cloud.unity3d.com;" always;
Also
add_header Content-Security-Policy "default-src https: data: 'unsafe-inline' 'unsafe-eval' 'self'; connect-src https: data: 'self' wss://*.relay.cloud.unity3d.com:37011;";
Also verified additional Unity relay Domains as:
connect-src https: data: 'self' wss://*.relay.cloud.unity3d.com:37011 wss://*.unity3d.com;
I am still in the process of figuring out how to resolve this issue. As shown in the attached images, the Lobby is successfully created, and the client connects via Unity Relay. However, after that, I encounter an error that prevents the game from starting and stops the client from connecting to the server.
If anyone has encountered this issue before, I would appreciate your guidance. Additionally, if I am using incorrect domains for Unity Relay or any other Unity Multiplayer Services, please let me know.
