One of the biggest downsides to using INETS, the built in web server in the Erlang runtime, is that it does not do multi homing straight out of the box. Because of this single migging feature I had though I would either rewrite the web server, or I’d end up using mochiweb. My goal with the Erlang Internet Framework is to have as few dependencies on other people code as I can, so finding a way to achieve multi homing without using (the really great) mochiweb and without rewriting the whole server was a big concern for me.
After playing around with different ideas for the better part of a day I came across a suitable work around, at least for me. I created a module called mod_multi and configured a server on port 80 (and 443) that only uses this one module. mod_multi basically will take any commands that it gets, figure out the host name, look to see if any other INETS servers on the local machine are running an instance with the server_name set to the Host Name and then it request the same URI on the loopback interface and on the port that is being used by the server that it has found.
There are a few assumptions that I make in order for this to work. The port for the internal web servers is always set to 0, this gives a random port number, and the bind_address is always set to 127.0.0.1, which is the loopback interface. Since the internal communications is being handled on the loopback interface I’m not as concerned with checking if it is going to use SSL, so all internal web servers have no need for SSL at this time. If I chage this in the future I’ll be sure to add support for internal SSL.
This is more of a proof of concept at this point, basically proving that mod_multi can perform the tasks needed to create multi homing on INETS. Although the downside to it is that it is a classic man in the middle attack template. I suppose to some extent any proxy server has all the code built in to create a man in the middle attack as well, but I just never realized exactly how easy it would to create one.
Ultimately this is destined to be part of my effort to turn EIF into a cloud based (read: AWS based) infrastructure application. now that I have gotten past this point, I’m going to look into a mod_s3 module that will allow a web server to grab it’s templates from S3 if it does not already have them and setup a way to update the template if they have changed. That way you could upload all of your HTML or ERML files to S3 and each time a page is accesses from a web server (within a reasonable amount of time) on EC2 it would check for updates and stay current.
With the thought of this being on S3, I may implement a way to allow other servers to be involved. That way one external IP address could accept all web connections and redirect them to other EC2 instances for processing. In fact I had been thinking about doing this on several protocols, including SMTP and IMAP; which would give one IP address as the face of all connections and you could have an army of servers behind it doing all of the tasks.






