I have made a good preparation: Apache 2.4 + PHP7 + WebSocket
Visit this link to see my preparation
details: Cannot load modules/mod_proxy_wstunnel.so into server
But when I run a simple WebSocket demo, I am meet with some problems. I have no idea how to solve them.
Websocket is a new concept to me. I have learned that Apache 2.4 supports WebSockets with mod_proxy_wstunnel.so.
My steps:
- Edit httpd.conf, load
mod_proxyandmod_proxy_wstunnel(of course both are in apachedir/modules)
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_wstunnel_module modules/mod_proxy_wstunnel.so
- Add proxy (still in httpd)
ProxyPass /ws ws://10.180.0.123/
ProxyPassReverse /ws ws://10.180.0.123/
- create HTML client and PHP server (
cd apachedir/htdocs)
client.html
<html>
<script>
var socket = new WebSocket("ws://10.180.0.123/server.php");
socket.onopen = function(e){
console.log("open success");
}
socket.onmessage = function(e){
console.log("mes:"+e);
}
//socket.close();
socket.send("Hello World");
</script>
<html>
server.php
<?php
echo "hello";
?>
4.start apache
/usr/local/apache2/bin/apachectl start
My questions:
- When I open:
10.180.0.123/client.html, I got the following error:
Uncaught InvalidStateError: Failed to execute 'send' on 'WebSocket': Still in CONNECTING state.
WebSocket connection to 'ws://10.180.0.123/server.php' failed: Error during WebSocket handshake: Unexpected response code: 200
I guess I should write some code in server.php, and run it. Am I right? And what should I write. I didn't find any information on google.
- When I open:
10.180.0.123/ws/client.html, I get the following Apache error logs
[Wed Sep 28 00:14:54.063989 2016] [proxy:warn] [pid 6646:tid 140326217934592] [client 10.230.0.93:57508] AH01144: No protocol handler was valid for the URL /ws/client.html. If you are using a DSO version of mod_proxy, make sure the proxy submodules are included in the configuration using LoadModule.
It seems the proxy module was not be loaded, but see my screenshot:
