How would I configure a websocket server to run alongside a webserver?
You can't have two services both listening on the same port, so you'll need a second IP address.
Honestly, if I were implementing this, I'd just use apache on the front end, using mod_proxy to proxy your game requests through to your custom server that would only be listening on localhost. That would do away with the necessity of having two IP addresses.
An idea: Set up a virtual host in your existing apache instance and set up an AJAX responder there, written in PHP, Python, or [your favourite language]. Your javascript client code makes AJAX calls to your apache vhost, and the AJAX responder makes whatever calls are necessary to your other server to satisfy client requests.
Have a look at reverse HTTP proxying!
It pretty much just redirects different requests to the specific ports, you could for example:
- have apache listening on port 8000
- your favorite websocket server listening on 8001
- have your reverse http proxying tool listen on port 80 and redirect
example.com/ws
to port 8001, and the rest to 8000
For example look at node-http-proxy, it is VERY easy to use, and there is even a simple example of websockets via socket.io
right there (of course you can use whatever you prefer for a ws server).
Edit: Also the mod_proxy
module of apache might be worth checking out, as an alternative (newer versions of apache also support a mod_proxy_wstunnel
module).