I have a single page application, this application is developed with .net CORE + ReactJS. I managed to run the application on centos 7 + plesk panel. I made the Apache settings in the Plesk panel, but the websocket gives an error. How can I solve it?
I get the following error when the application runs.
WebSocket connection to 'wss://mydomaindomain.xyz/hubCon?id=epgy-kgVtR9HU7kxgErVAQ&access_token=eyJhbGciOiJodHRwOi8vd3d3LnczLm9yZy8yMDAxLzA0L3htbGRzaWctbW9yZSNobWFjLXNoYTI1NiIsInR5cCI6IkpXVCJ9...................
[2021-07-26T15:18:08.636Z] Error: Failed to start the transport 'WebSockets': null
Here is the Apache settings section in the Plesk panel.
Header set Access-Control-Allow-Origin "http://mydomaindomain.xyz"
Header set Access-Control-Allow-Headers "Access-Control-Allow-Headers, Origin, Accept, X-Requested-With, Content-Type, Access-Control-Request-Method, Access-Control-Request-Headers, Authorization, Content-Disposition"
Header set Access-Control-Allow-Methods "*"
Header set Access-Control-Allow-Credentials "true"
ProxyPreserveHost On
ProxyPass / http://127.0.0.1:5000/
ProxyPassReverse / http://127.0.0.1:5000/
I solved the problem, put the code below in the nginx section under apache & nginx settings in the plesk panel, the problem will be solved.
location ^~ /yourSocketName {
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Frame-Options SAMEORIGIN;
proxy_pass http://127.0.0.1:5000;
}