Once the server is running and you have dealt with any error messages, the next step is to test it. The most obvious way to test a Web server is with a Web browser, but you can also test from the command line. Before trying to test the server, create a short but valid home page, so Apache has something to send. You can use the page Apache installs by default or put together your own, for example:
This is a somewhat minimal HTML document, but it’s good enough for testing purposes. Put this in a file called index.htm or index.html and place it in the directory specified as the document root in Apache’s configuration. NOTE If no document root has been specified, Apache looks for a directory called htdocs under the server root. If neither the server root nor the document root is defined, the default home page would be /usr/local/apache/htdocs/index.html . Testing with a BrowserThe simplest and most obvious approach is to start a Web browser and point it at the server using the server’s configured root domain name if it has one, or localhost, which should work on any Unix system. Alternatively, the configured IP address of the server should also work:
Apache needs to know what domain or domains it’s to handle, but it’s not responsible for managing them, only responding to them. In version 1.3, Apache listens to all valid IP addresses for the host it’s running on by default, so an attempt to contact any valid network name or IP address for the host with a browser should cause Apache to respond. Apache 2 requires that you specify at least one Listen directive; it determines whether Apache will receive the connection request. If you’re setting up Apache to use a particular domain name but don’t yet have a proper IP address for it, you can associate www.alpha-complex.com in this example with the loopback IP address 127.0.0.1 as a temporary stand-in, which will allow the domain name to work without a real network interface in place. NOTE For more information on domain names and IP, see the introductory section about TCP/IP networking in Chapter 1 and the Listen directive. Testing from the Command Line or a Terminal ProgramIt’s also possible to test the server either directly from the command line or by using a basic terminal program. This can be especially handy when checking the values of response headers that are otherwise hard to see. On Unix systems, the telnet command can be used to make a network connection to the server. On other operating systems, a telnet utility is usually available, and syntax and location vary from system to system. Most browsers support a telnet mode. To contact the server with telnet, type the following under both Windows and Unix:
If Apache is running and responding to connections, this should produce something similar to the following (some telnet commands are more verbose than others):
At this point, you may type in any valid HTTP protocol command, and if the server is working correctly, you can expect a response. For example, the following will return a short informational message about the server:
Because HTTP 1.0 and newer allows you to send additional information in the form of additional header lines, you need to press the Return key twice after this command to let the server know the whole request has been sent. What does this mean? HEAD tells the server you just want header information. The / is the URL you want, which needs to be valid even if you don’t actually want the page; / must be valid on any server, so it’s safe to use here. HTTP/1.0 tells Apache you’re sending a version 1.0 HTTP command. Without the HEAD command, Apache will assume that you’re sending HTTP 0.9 commands because the HEAD command was introduced in HTTP 1.0. You’ll need to explicitly set the HTTP version, or Apache will return the following error:
If the server is working correctly, HEAD / HTTP/1.0 should produce something like this, depending on the exact configuration:
This tells you what version of HTTP Apache supports (1.1 for any version from 1.2 and newer), the time of the request, and the server type and version. In this case, Apache, of course, plus the operating system. Connection: close tells you that Apache will close the connection after responding, and Content-Type tells you what kind of document you asked about. This particular home page is an HTML document. If the server responds to a HEAD command, it’s time to try to retrieve the homepage of the Web site with this:
This will cause Apache to interpret the request as an HTTP version 0.9 command and should produce the homepage:
You could also use a protocol parameter to tell Apache you want to use HTTP version 1.0:
If you do this, you have to press Return twice to tell Apache you don’t want to send any headers. If you were to specify HTTP/1.1, you would be obliged to send a hostname as a header. You could do this anyway with either 1.1 or 1.0, and if there are virtual hosts set up, you can test each one individually, for example:
and:
If Apache responds correctly to each GET request with the appropriate home page, you have a working server. Unless it has been configured otherwise with the KeepAlive directive, Apache will keep a connection open after handling an HTTP/1.1 request. This allows you to type in another request immediately. With HTTP/1.0, the connection is dropped after the response is sent.
blog comments powered by Disqus |
|
|
|
|
|
|
|