Configuring, Tuning and Debugging Apache
Once your Apache server is compiled, installed, configured and running, you might still encounter some problems. apachectl configtest is a good way to ensure that all of the directives are legal—but this does not ensure that they will work, nor that they are the values you really want.
A good tool for checking that a server is working in the right way is telnet. Telnet is probably familiar to most Linux users as a way to log into one computer while sitting at another. However, telnet can open a TCP connection on any port, not just the default port 23 used for the “telnet” protocol. You can thus use telnet for SMTP (port 25), POP (port 110) and even HTTP (port 80). This is a great way to test web servers to see if they're running, as well as run some basic tests.
The key to this technique is understanding that every TCP/IP service is associated with an IP address and port on both the origin and destination computers. Thus, a telnet connection between two computers will almost certainly include two IP addresses, an arbitrary port on the client, and the well-known port 23 on the server. Similarly, an SMTP connection carrying e-mail between two computers will normally include a connection from an arbitrary port on the client to port 25 on the server. For a list of well-known ports, including many that should not be changed without good reason (such as FTP, SMTP, telnet), look at the standard file /etc/services on any computer running Linux.
To use the telnet program to connect to an arbitrary port, simply indicate the port number (or name, if one appears in /etc/services). For example, to connect to the HTTP server running on port 80 of the computer www.lerner.co.il, simply say telnet www.lerner.co.il 80.
If the server is running on a different port, as defined by the Apache Listen and Port directives, simply specify a different number. For example, if the server is running on port 8080, we can connect to it with telnet www.lerner.co.il 8080.
Of course, a single Apache process can handle input on two or more port numbers, so long as they are specified correctly in httpd.conf.
If no server is running on the specified port, then telnet will exit with a fatal “connection refused” error. In such a case, consult the Apache error logs, normally placed in /usr/local/apache/logs/error_log, to determine the source of the problem.
If an HTTP server is indeed running on the specified port, then telnet will display a message indicating how to exit back into the telnet command prompt (usually with CONTROL-]), and will then connect you. What prompt you see depends on the type of server to which you connect; while SMTP, FTP and POP all greet an incoming user with the name of the server computer, HTTP is unusually silent. The assumption is that you know the name of the server to which you have connected, and that the connection was obviously successful.
At this point, you can issue an HTTP request. The simplest form of request is GET /, followed by a single newline character. This is an HTTP request of the most primitive sort, which is no longer used but is built into HTTP servers in order to ensure backward compatibility with older clients. Soon after pressing ENTER, you should see the contents of the root (or “index”) page of the site to which you connected. It may be difficult to read the unparsed HTML at first, but remember that this is a simple debugging method.
A more sophisticated request uses HTTP/1.0, the first version of HTTP to include headers in the request and response. The request and response are each preceded by one or more “header” lines, containing a header name, a colon and a text string. The headers and request/response body are separated by a single blank line.
Our simple request can thus be rewritten as GET / HTTP/1.0, with the latter part tacked on to indicate that our client understands a more sophisticated version of HTTP. We then have to press ENTER twice—once to indicate the end of this line, and a second time to indicate that we don't want to send any headers between the command line and the body of the HTTP request.
You can also submit name-value pairs to the server with telnet, separating each name from its corresponding value with “=”, and each pair with an ampersand. Normally, such arguments are passed in a GET request to a CGI program or other dynamic content producer. For example:
GET /cgi-bin/foo.pl?name1=val1&name2=val2 HTTP/1.0 After pressing ENTER twice, you should see a set of response headers, followed by whatever output is produced by the CGI program foo.pl. You can also pass headers along with the request. After pressing ENTER following the initial GET line, type one or more headers, with a new line after each one. For example:
GET /cgi-bin/foo.pl?name1=val1&name2=val2 HTTP/1.0 Accepts: text/html Accept-language: text/html Following the final header, press ENTER twice—once to finish the header, and again to indicate that the request is complete.
- Readers' Choice Awards 2014
- Handling the workloads of the Future
- Android Candy: Google Keep
- diff -u: What's New in Kernel Development
- How Can We Get Business to Care about Freedom, Openness and Interoperability?
- Synchronize Your Life with ownCloud
- Days Between Dates?
- December 2014 Issue of Linux Journal: Readers' Choice
- Non-Linux FOSS: Don't Type All Those Words!
Editorial Advisory Panel
Thank you to our 2014 Editorial Advisors!
- Jeff Parent
- Brad Baillio
- Nick Baronian
- Steve Case
- Chadalavada Kalyana
- Caleb Cullen
- Keir Davis
- Michael Eager
- Nick Faltys
- Dennis Frey
- Philip Jacob
- Jay Kruizenga
- Steve Marquez
- Dave McAllister
- Craig Oda
- Mike Roberts
- Chris Stark
- Patrick Swartz
- David Lynch
- Alicia Gibb
- Thomas Quinlan
- Carson McDonald
- Kristen Shoemaker
- Charnell Luchich
- James Walker
- Victor Gregorio
- Hari Boukis
- Brian Conner
- David Lane