How to setup websockets with PHP in nginx?
I have looked at this tutorial, but cant make it work
https://www.sanwebe.com/2013/05/chat-using-websocket-php-socket
Have copied the three files into the root of the www directory
/index.php
/jquery-3.1.1.js
/websocket/server.php
In index.php I have changed the URI
var wsUri = "wss://domain.com/websocket/server.php";
In nginx I have added this
http {
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
server {
location /websocket/ {
proxy_pass https://domain.com:9000/websocket/server.php;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
}
}
}
http://nginx.org/en/docs/http/websocket.html
To start websocket server
php -q /var/www/websocket/server.php
The chat is located at https://domain.com/chat.php and loads but get this error in the chat window Error Occurred - Connection closed
Have also tried to connect through this tool, but get this error
http://www.websocket.org/echo.html
ERROR: undefined
DISCONNECTED
If requested through browser
wss://domain.com/websocket/server.php
ERR_DISALLOWED_URL_SCHEME
tcpdumpto check if the setup is working as expected on the network level.