Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

So, I've got a WebSocket server in C++, that is a completely stand-alone entity - handles header parsing, receiving, sending, all of it on its own, listening directly to the port.

Problem is, it needs to run on a server alongside Apache, and that's a bit of a problem. Now, there was a solution here to a similar issue involving mod_proxy, but I'm hoping I can intercept and redirect WebSocket communication before Apache even knows about it, possibly with iptables.

So the question is, is it possible to direct traffic bound for to a WebSocket server on, say, port 8080, while anything else headed to proceeds as expected to Apache?

share|improve this question
Not if they have the same IP address. You need HTTP header inspection to figure out if it's a websocket connection. – David Schwartz Nov 5 '12 at 23:06
up vote 2 down vote accepted

It turns out this is actually pretty easy; just code the client to access the server at ws:// With all the touting of WebSockets being able to use port 80, I was quite surprised to learn it doesn't need to.

share|improve this answer

Sorry, it's not possible with iptables because iptables doesn't speak/understand http protocol. Someone should write ip_conntrack_http so this could actually work (something similar as ftp conntrack thingie) ;-) Till then you should probably use apache with mod_proxy or nginx.

share|improve this answer
I'm assuming that both servers are binded to the same IP address because otherwise this question doesn't make much sense (the answer would be too simple) – FINESEC Nov 5 '12 at 23:20

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.