How does a Webserver actually work? Find out with nweb
nagger 100000MRSJ Visits (6156)
I have just updated my article on DeveloperWorks that cover the nweb Webserver.
You can find the new link to the new page here: nweb
The previous DeveloperWorks link now mysteriously fails
I wrote the nweb Webserver as example C code to show the concepts and details of how they work.
It was under 100 lines but I thought it actually was a pretty useful tool and used it, for real, in a number of projects and others have used it too. Then I though I had better put in some safety checks - otherwise you could give away read access to ALL the files on your AIX, UNIX or Linux system!! So there are directories that it will refuse to start in and you can't access above the top level directory of the webserver files. It also shows how a process can turn itself in to a demon - so it carries on when you log out. nweb is called a static page server - it will simply send back any requested page which means a file (the files have to end with one of a list of file types like .html, .jpg, .gif etc. as a further sanity check). It does nothing fancy like running CGI scripts or Perl or PHP extensions. This means it is safe and you can't muck up the configuration and leave your system exposed. These extras have meant it is now 200 lines of code. But then I though hang-on, it might be small but it includes a lot of concepts, system calls and non-obvious programming and you need to understand a little HTML and the minimum WWW protocol, so the article is many times the size of the concise code. Not bad for 200 lines or 7610 bytes of C code!
There is also a picture of me on the included tiny test website. It is taken at an IBM building, which was used in one of the James Bond movies. Teri Hatcher touched the same railing in Tomorrow Never Dies. Now you have to download it and watch the movie again :-)
Legal License side step
As it is simple C systems programming code that any genius C programmer (like me :-) would write in a similar way, I gave it away as sample code and not needing a legal license to use, reuse or anything else you like. This nicely avoids any legal issues because even IBMers can give away obvious sample code - once you understand all the public domain principles.
So what do you want?
So it you want to learn something about:
then got to the website and/or download the nweb package from the website above as it comes to just 48 KB for the C code, the picture and 5 compiled binaries.
Thanks Nigel Griffiths