Web servers
Introduction
The term 'Web server' can be used to refer to a software program which serves Web content, or to a computer running such a program.
Web server: software
A Web server program is a piece of software that can handle requests across the Internet for Web pages, graphics, and related files.
Web servers accept requests from clients (Web browser programs running on user computers), and send responses to those requests. A response might be the requested file, or it might be an error message explaining why the server cannot provide the requested file.
Web server: hardware
The term 'Web server' can also be used to refer to the computer which is running the server software. Generally, this computer will have a fast, permanent Internet connection, but more or less any computer can be used. Web serving doesn't require high-performance computers; many people use old hardware such as 486s to serve small Web sites.
HTTP
HTTP is a standard used for communication between Web browsers (such as Netscape or Internet Explorer) and Web servers (such as Apache or Internet Information Server).
HyperText Transfer Protocol
HTTP is the protocol which underpins the Web. You may recognise the initials from the beginning of URLs which, when given in full, read 'http://www.somewhere.com/'. The 'http:' instructs your Web browser to use the HTTP protocol when communicating with the server at www.somewhere.com.
Communication standard
A 'protocol' is a defined communication standard; a list of commands and responses which computers can use to communicate with each other.
Request
A program wishing to obtain information from a Web server must connect to that machine and send an HTTP request to the machine. The request specifies the desired file and also includes 'headers' with additional information such as the name of the requesting program, cookies for the site, etc.
For example, a request for the file 'http://www.somewhere.com/something.html' would be made by connecting to www.somewhere.com and sending an HTTP request beginning 'GET /something.html HTTP/1.1'.
Response
When the server receives an HTTP request, it replies by sending an HTTP response. This response contains some informational headers about the type of response (whether it is a successful response, an error, or somewhere in between) and giving the type (text, picture, etc.) of the file requested, as well as the actual data.
Requesting a simple Web page
This page follows the sequence of events involved in requesting a simple Web page with one picture.
Example page
As an example, we take a page including a small amount of text and a single picture. The part of page with a picture might look like this:
<img src="pic.gif" alt="My picture">
We assume this page is available on the Web at http://www.mycomputer.com/test.html.
1. (Browser) Request page
The browser first connects to www.mycomputer.com and sends an HTTP request for the file /test.html.
2. (Server) Send page
The server receives a request for /test.html. It checks to see that the file exists. When it finds the file, it then sends an HTTP response containing the file contents back to the browser.
3. (Browser) Receive page
The browser receives the HTML response. It checks the type of response; because the response was a standard (non-error) response, no special action is taken. Because the file retrieved is an HTML file (of the text/html MIME type), the browser can display it, rather than saving it to disk or running some other program.
4. (Browser) Display page
The browser then processes and displays the HTML file. The file contained an image request, but it doesn't have the image yet, so it displays a placeholder and sends a request to the same server for the image file /pic.gif.
5. (Server) Send error
The server receives a request for /pic.gif. Just as last time, it checks that the file is present; unfortunately in this case it is not. So, rather than sending the file, it responds with an error code 404 ('File not found').
6. (Browser) Receive error
Finally, the browser receives a 404 response to its request for pic.gif. Because it now knows the picture is not valid, it redraws the page with a 'broken image' icon for the picture, containing the alternative text. (If the picture had been valid, it would have redrawn the page with the picture.)
The page load is now complete.
Web server complexities
Client/server
HTTP is a client/server system. The browser is a 'client'. It connects to a 'server' to obtain the necessary data. The term 'client' is frequently used; in this context, it's interchangeable with 'browser'.
Dynamic content
The server doesn't have to simply send a file in response to user requests. It can run other software, make calculations, and so on. As long as it sends an HTTP response, it doesn't matter what happened in creating that response.
For example, a request for '/test.cgi?name=sam' might result in the Web server actually running a separate program called test.cgi with the parameter 'name=sam', and sending back the results of that program to the client browser.
One server, multiple sites
A single Web server can handle many Web sites, and you can make many computer address names point to the same name (e.g. leafdigital.com is actually the same computer as gwind.pair.com). The server knows which site is being requested because HTTP requests contain, as one of the headers, the named address. So it can send out the appropriate response file.
Summary
Web servers send the HTML files (and other associated content) to Web browsers.
HTTP
Web browsers and servers use the HyperText Transfer Protocol, a communications standard which means that different types of browser can communicate with different types of server, as long as they all support HTTP.
Request/response
To retrieve a page, your browser sends an HTTP request to a server. The server sends back an HTTP response with the content of the page.
One page, many requests
Because many files may make up a single Web page (the HTML, the graphics, the stylesheets, etc.), obtaining a single Web page may involve many HTTP requests and responses.