Subscriptions working on localhost but not working on host

When I request any subscription on the local server it works fine but does not work on the hosting server and at the same time the rest of the queries work correctly.

This is the error message:

“error”: “Could not connect to websocket endpoint wss://example.com/graphql. Please check if the endpoint url is correct.”