IBM Support

How does a Webserver actually work? Find out with nweb

How To


Summary

Where to find out the bascis of a web server, if you know a little C programming - or at least can read C Code to understand the principles.

Objective

Nigels Banner

Steps

My article on the nweb web server is updated and moved to SourceForge.net

 nweb Tiny Safe Static web server C code example of the nmon for Linux wiki

I wrote the nweb web server as an example C code to show the concepts and details of how web servers work.
It was under 100 lines but I thought it was a useful tool and used it in a number of projects. Other people use it too in their projects.  Then I thought 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 refuses to start in and you can't access above the top-level directory of the web server files.  It also shows how a process can turn itself into 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.  The files have to end with one of a list of known 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 extra check has grown the code to 200 lines - still small.  But then I thought hang on might be small but it includes a lot of concepts, system calls and nonobvious programming techniques 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!
The article covers the principles and pseudocode algorithms that anyone should understand. It covers the basics of HTTP and HTML protocols. To learn the details, you will need basic C coding skills but the code is straightforward (no doubly linked lists here or pointers to functions). 
Bonus time!
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 decided to 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.
So what do you want?
So it you want to learn something about:
  1. How a browser asks for files from a web server (GET and HTTP/1.1 200 OK).
  2. The algorithm inside a web server.
  3. The system calls to control remote network connection (socket, listen, accept).
  4. The system calls to create a demon process.
  5. Or have a usable static web server binary with zero configuration for AIX 6, Ubuntu 12.4, Fedora 17, Open-SUSE 12, and Raspberry Pi Debian.
  6. C source code from a genius :-)
  7. Some small but interesting C programs to muck about with and learn C from or add to!
Then, got to the website and download the nweb package from the nweb website. You get just 48 KB for the C code, a tiny web page, the picture, and 5 compiled binaries.
Thanks, Nigel Griffiths
 

Additional Information


Other places to find content from Nigel Griffiths IBM (retired)

Document Location

Worldwide

[{"Business Unit":{"code":"BU058","label":"IBM Infrastructure w\/TPS"},"Product":{"code":"SWG10","label":"AIX"},"Component":"","Platform":[{"code":"PF002","label":"AIX"}],"Version":"All Versions","Edition":"","Line of Business":{"code":"LOB08","label":"Cognitive Systems"}},{"Business Unit":{"code":"BU054","label":"Systems w\/TPS"},"Product":{"code":"HW1W1","label":"Power -\u003EPowerLinux"},"Component":"","Platform":[{"code":"PF016","label":"Linux"}],"Version":"All Versions","Edition":"","Line of Business":{"code":"","label":""}},{"Business Unit":{"code":"BU058","label":"IBM Infrastructure w\/TPS"},"Product":{"code":"SWG60","label":"IBM i"},"Component":"","Platform":[{"code":"PF012","label":"IBM i"}],"Version":"All Versions","Edition":"","Line of Business":{"code":"LOB57","label":"Power"}}]

Document Information

Modified date:
14 June 2023

UID

ibm11165582