Chapter 15: Web Servers in Linux

 < Day Day Up > 



Introduction

A Web server is a computer that runs software that serves up Web pages. When you visit a Web site such as that for this book’s publisher, www.charlesriver.com/, your browser connects to that machine, probably after connecting to your Internet service provider and a veritable host of intermediate sites or routers, and requests an HTML document from that machine. That machine then serves up that HTML document, and thus we have a Web server. That explains what a Web server is, but not why you might want one. In earlier chapters we discussed briefly how to develop your own Web pages, using some of the tools that come with Red Hat Linux 9.0. You can then use a commercial or free Web hosting service. But what if you want to host those Web pages from your home machine? Or what if you are administering a small network in an office and want to provide a Web site for the office, or just an internal Web site for people in that office to use? In any of these scenarios you might want your own Web server. Fortunately for you, Linux provides such Web servers.

Red Hat ships with a very popular Web server, the Apache server, which we will examine in detail in this chapter. There are also several free or low-cost Web servers you can download from the Internet. We will briefly discuss some of these later in this chapter. At the end of this chapter you should have a basic understanding of what Web servers are, how they work, and how to set up the Apache Web server.

How Do Web Servers Work?

It is possible that you could set up and run the Apache Web server and not really understand how it is working. Such a course of action is bound to be fraught with problems. Anytime you are operating technology and have no idea how or why it works, you are asking for problems. For this reason we will take a few moments to discuss how Web servers work and communicate.

To begin with, recall that every type of communication that a computer does is handled by some sort of protocol. You have already learned that e-mail is sent using SMTP (Simple Mail Transfer Protocol) on port 25 and received using POP3 (Post Office Protocol Version 3) on port 110. You also learned that files are uploaded or downloaded on the Internet using FTP (File Transfer Protocol), and it works on port 21. Web communication is no different. It uses HTTP (Hypertext Transfer Protocol) and works on port 80.

HTTP works by requests and responses. A Web browser sends a specific request to an address. That address can be either an IP address such as 10.10.10.01 or a URL such as www.chuckeasttom.com. The Web server that is at that address then sends back a specific response. In essence a Web server is any computer that has some program on it that can listen to port 80 and respond to the HTTP requests it receives.

Note 

Just for your information, IP stands for Internet Protocol, and URL stands for Uniform Resource Locator. It is basically just a technical way of saying Web address.

How does a Web server respond when it gets this request? It begins by sending back a numeric code to the Web browser that sent the request. That code tells the browser what is happening on the server side. Have you ever seen a Web page response like “HTTP 404 - File Not Found,” as shown in Figure 15.1a? The number 404 is the error code that all Web servers send to browsers if they cannot find the Web page that the browser requested.

click to expand
Figure 15.1A: Error message 404.

If the response is that the request was OK and the server is processing it, then the server will respond by sending the appropriate HTML document to the Web browser that was requesting that document. The browser then loads that document into memory and displays it in the browser. The basic process of sending and receiving requests between a Web browser, your ISP, and a Web server is diagrammed in Figure 15.1b.

click to expand
Figure 15.1B: The process.

There are a number of codes that a Web server can send back to a browser. Some of the more common codes are listed in Table 15.1. It is important that you remember two facts. The first is that these error codes are the same regardless of the browser making the request or the Web server answering the request. An Internet Explorer browser connecting to a Microsoft Internet Information Server® Web server will get the same codes that a Mozilla browser connecting to an Apache Web server will get. The second fact to keep in mind is that the browser will not display some codes to you. For example, if the code indicates that the Web page was found and is being sent, then that code will not be displayed. Usually your browser will only display those codes that indicate an error of some type has occurred.

Table 15.1: HTTP Return Codes

Code

Meaning

101

This is an indication that the browser has asked to switch protocols (maybe to download a file, so it is switching to FTP) and the server is agreeing.

200

This is just an OK message.

202

The request has been accepted.

301

The page has been moved and you are being redirected to the new address.

401

The browser is not authorized to do whatever it is attempting.

404

The requested file could not be found.

504

Server timed out.

Some of these response codes you would never see. The browser would process them. Some, like 401, 404, and 504, you will probably see at some point in your Web surfing. It is not necessary for you to commit this list to memory. What is important is that you understand what is going on in the background when you use your Web browser to visit some Web site. Messages are being sent from your browser to the server. On the server end, some software is listening in to port 80 for standard browser requests and then responding. That is the essence of a Web server. Now keep in mind that commercial Web servers are generally run on very high-end computers with backup hard drives, lots of memory, and lots of processor power. However, you can certainly run a Web site from your personal computer. It just won’t be able to handle thousands of visitors every day.

This leads us to the Web server software. There are several programs available that will listen on port 80 and respond to HTTP requests. Some are easier to use than others. Also, some work on one operating system but not another. The two most commonly used are Microsoft’s Internet Information Server, commonly called IIS, and the Apache Web Server from www.apache.org. Since IIS is strictly for Windows, we will devote much of this chapter to Apache.

Note 

You can go to www.netcraft.org and type in any Web site’s address. It will then tell you what kind of Web server that Web site is using.



 < Day Day Up > 



Moving From Windows to Linux
Moving From Windows To Linux (Charles River Media Networking/Security)
ISBN: 1584502800
EAN: 2147483647
Year: 2004
Pages: 247
Authors: Chuck Easttom

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net