Apache Server Survival Guide asg02.htm
|
If you don't have access to a compiler, you can still install Apache provided that you can find a precompiled version of the server that works with your hardware and operating system. I have included the precompiled servers I found at the Apache group's Web server, including AUX 3.1, BSDI 1.1 and 2.0, FREEBSD 2.1, HPUX 9.07, IRIX 5.3, Linux, NETBSD 1.1, SOLARIS 2.4, SunOS 4.1.3, and UNIXWARE 1.1.2., and others. Fig. 2.1 The Apache home page. Notice this site is mirrored around the world.
The Apache site provides links to various mirror sites from which you can download the software. Choose the one that is geographically closest to you from the various sites listed on the Apache home page.
To install Apache in its default location at /usr/local/etc/httpd, you may need to be the superuser. You'll need to know the root password of the machine in which you are installing Apache. If you don't know how to become root, please contact your local system administrator. Put the distribution archive in the /tmp directory. A sequence of commands to do the installation from /tmp might look like this:
|
mkdirs /usr/local/etc (your system may use 'mkdir -p /usr/local/etc' instead) cd /usr/local/etc mv /tmp/apache_1.1.1.tar.gz /usr/local/etc gzcat apache_1.1.1.tar.gz | tar -xf - mv apache_1.1.1 httpd |
|
ServerAdmim | The ServerAdmin directive should be set to the address of the webmaster managing the server. It should be a valid e-mail address or alias, such as webmaster@your.domain. Setting this to a valid address is important because this address will be returned to a visitor when there's a problem. |
User and Group | The User and Group directives set the UID and group ID (GID) that the server will use to process requests. I kept these to the defaults: nobody and nogroup. Please verify that the names nobody and nogroup exist in your /etc/passwd and /etc/group files, respectively. If you want to use a different UID or GID, go ahead; however, be aware that the server will run with the permissions you define here. The permissions for the specified UID and GID should be very low because, in case of a security hole, whether on the server or (more likely) on your own CGI programs, those programs will run with the assigned UID. If the server runs as root or some other privileged user, someone may exploit the security holes and do nasty things to your site. Instead of specifying the User and Group directives using a name, you can specify them by using the UID and GID numbers. If you use numbers, be sure that the numbers you specify correspond to the user and group you want, and that they are preceded by the pound (#) symbol. |
Here's how these directives would look if specified by name:
User nobody Group nogroup
Here's the same specification, but by UID and GID:
User #-1 Group #-1
ServerName | The ServerName directive sets the hostname the server will return. Set it to a fully qualified domain name (fqdn). If not set, the server will try figure it out by itself and set to its canonical name. However, you may want the server to return a friendlier address such as www.your.domain. Whatever you do, ServerName should be a real Domain Name System (DNS) name for your network. If you are administering your own DNS, remember to add a CNAME alias for your host. If someone else manages the DNS for you, ask her to do this for you. Your ServerName entry should look like this: ServerName www.your.domain |
ServerRoot | This directive sets the absolute path to your server directory (where your httpd binary is located). This directive tells the server where to find all the resources and configuration files. Many of these resources are specified in the configuration files relative of the ServerRoot directory. If you installed your server using my examples, your ServerRoot directive will read: ServerRoot /usr/local/etc/httpd |
|
DocumentRoot | Set this directive to the absolute path of your document tree. Your document tree is the top directory from which Apache will serve files. By default it is set to /usr/local/etc/httpd/htdocs. |
You may also want to set the UserDir directive to disabled. The UserDir directive defines the directory relative of a local user's home directory where they will put public HTML documents. It's relative because each user will have a public_HTML directory. Although this may give users at your site the freedom to create and maintain their own home pages, many users may not be aware of this fact, resulting in the possibility of their creating a public_html directory that contains private files. Additionally, depending on the kind of users in your system and the server configuration, this may create potential security problems. It would make it possible for a user to publish your entire filesystem by creating a symbolic link to a directory outside of a Web document tree. By doing this, anyone would be able to read and navigate your filesystem freely.
Chapter 16, "Web Server Security Issues," discusses alternatives for providing this functionality that I feel are better from a security and maintenance standpoint.
A copy of the boilerplate conf/srm.conf file has been included at the end of this chapter.
|
httpd stream tcp nowait nobody /usr/local/etc/httpd/httpd httpd -f /usr/ local/etc/httpd/conf/httpd.conf |
If you specify the root UID in this example with the intention of running the inetd server on port 80, the process handling the request is owned by root. This may create security problems; unlike a standalone server, the inetd server doesn't fork any children processes, so it handles requests with the UID and GID of the process owner. After adding the httpd entry to /etc/inetd.conf, you'll need to restart inetd. You can easily do this by finding out the inetd process number with ps and sending it a HANGUP signal:
# kill -HUP InetdProcessID Replace the InetdProcessID with the process number listed by the ps command. If the PID listed was 86, you would type kill -HUP 86.
inetd will restart, rereading its configuration file that will instruct it to listen for request for port 8080.
|
<HTML> <HEAD> <TITLE>Apache Server Survival Guide</TITLE> </HEAD> <BODY BGCOLOR="#ffffff" LINK="#000080" VLINK="#000080"> <H1><CENTER>Apache Server Survival Guide </CENTER></H1> <H2><CENTER>Congratulations! Your Apache server was successfully installed.</CENTER></H2> <H3>Here are some interesting sites that host information about the Apache server: </H3> <UL> <LI>The official homepage for the <A HREF="http://www.apache.org">Apache Group</A> <LI>The official homepage for <A HREF="http://www.us.apache-ssl.com">Community Connexion</A> developers of Stronghold: Apache-SSL-US (A Netscape compatible SSL server based on Apache) <LI>The official homepage for <A HREF="http://www.algroup.co.uk/Apache-SSL">Apache-SSL</A> (A Netscape compatible SSL server based on Apache - only available to users outside of the United States). <LI><A HREF="http://www.zyzzyva.com/server/module_registry/"> Apache Module Registry</A>, the place where you can find information about 3<SUP>rd</SUP> party Apache modules and other development stuff. <LI><A HREF="http://www.apacheweek.com">The Apache Week Home</A>, here you will find an essential weekly guide dedicated to Apache server nformation. <LI><A HREF="http://www.ukweb.com">UK Web's Apache Support Center</A> <LI><A HREF="http://www.fastcgi.com">The FastCGI Website</A> </UL> <P> <STRONG>Deja News a very handy USENET news search engine:</STRONG> <FORM ACTION="http://search.dejanews.com/dnquery.xp" METHOD=POST> <P> <CENTER> <STRONG>Quick Search For:</STRONG> <INPUT NAME="query" VALUE="Apache" SIZE="37"> <INPUT TYPE="submit" VALUE="Search!"><INPUT NAME="defaultOp" VALUE="AND" TYPE="hidden"> <INPUT NAME="svcclass" VALUE="dncurrent" TYPE="hidden"> <INPUT NAME="maxhits" VALUE="20" TYPE="hidden"> </CENTER> </FORM> </BODY> </HTML> |
|
httpd: could not open document config file /usr/local/etc/httpd/conf/httpd.conf fopen: No such file or directory |
Check for typos or incorrect path information on your command line or in the configuration files. Typically this problem appears if you have customized your installation to a different directory. Apache has compiled-in defaults that preset the location of ServerRoot. If you specify a relative path, the server prefixes the compiled-in ServerRoot instead.
Other problems may have dump values such as
httpd: could not bind to port bind: Address already in use If you get this message, more than likely there's another process using the port number you have defined. Other port binding problems can show up if you specify a reserved port number (one whose address is smaller than 1025). Only root processes can bind to reserved ports. The solution is to start the server as root so that the server can bind properly to the specified port (if you have followed our instructions, your server although started by root, runs as nobody).
If the server doesn't respond, check to see if it is running. Use the ps program to see what's going on:
ps -guax | grep httpd (on BSD-type systems)
ps -ef | grep httpd (on SVR4-type systems)
Don't get worried if you see several httpd processes running. Apache's server model runs several simultaneous processes coordinated by the parent process (the one owned by root).
Sometimes Apache returns enough information that will help you track a problem to a bad configuration setting. Other times, you'll have to hunt for the error. The first thing to check are the logs/error_log and logs/access_log files for more information. While you're at it, you may want to check for any core files in the ServerRoot. If some problem is crashing Apache (I've never had one that dumped core), it's likely that it left a trace there.
|
# Config file for the Apache httpd. # Configuration.tmpl is the template for Configuration. Configuration should # be edited to select system type. Configuration.tmpl should only be changed # when a new system or module is added, or an existing one modified. # There are three types of lines here: # '#' comments, distinguished by having a '#' as the first non-blank character # # Lines which set a Make option --- these are simply copied into the Makefile # # Module selection lines, distinguished by having 'Module' at the front. # These list the configured modules, in priority order (highest priority # first). They're down at the bottom. # First, ordinary compile-time configuration. # What to call the compiler: For normal machines with ANSI compilers # CC= cc # For Suns or other non-ANSI platforms. Please make sure your gcc is # 2.0 or later, as 1.40 seems to create bad code for the Sun 4. CC= gcc # CFLAGS, compile flags. # -DMINIMAL_DNS is now obsolete. Use httpd.conf settings of # HostnameLookups on # or # HostnameLookups off # # If you want to have more secure hostname resolution at the cost of some # performance, use -DMAXIMUM_DNS. # If you want setting the xbit of a file to cause it to be treated as # server-included HTML (unless it is a CGI script), say -DXBITHACK. Note # that this is a run-time option, per-directory, either way (via the XBITHACK # command); this option only sets the default. # If you find that your OS can't cope with mmap (compiles OKAY but refuses # to run and moans "httpd: Could not mmap memory" .. or similar) try # disabling use of shared memory for process management (scoreboard with # -DNO_MMAP # Status Instrumentation # In order for the status module to obtain full statistics Apache must # be modified to keep track of various information. This is not # turned on by default. In order to enable full status details add -DSTATUS # to the end of the CFLAGS line below. # Using SOCKS # Apache can be compiled to work over a SOCKS firewall by # adding the following string to your CFLAGS define: # # -Dconnect=Rconnect -Dselect=Rselect -Dgethostbyname=Rgethostbyname # # and by adding the following to the EXTRA_LIBS define: # # -L/usr/local/lib -lsocks # # making sure that -L points to wherever you've put libsocks.a. # [Some other former Apache compile-time options are now treated differently; # the virtual host code is always present; DBM auth is an optional module, and # may be configured out by changing the module config below, though it still # defaults in. Note that this config file does not include DBM auth by # default --- configure it in below if you need it]. CFLAGS= -O2 # Place here any flags you may need upon linking, such as a flag to # prevent dynamic linking (if desired) LFLAGS= # Place here any extra libraries you may need to link to. # -lndbm is commonly required for DBM auth, if that is configured in. EXTRA_LIBS= # AUX_CFLAGS are system-specific control flags. # NOTE: IF YOU DO NOT CHOOSE ONE OF THESE, EDIT httpd.h AND CHOOSE # SETTINGS FOR THE SYSTEM FLAGS. IF YOU DON'T, BAD THINGS WILL HAPPEN. # For SunOS 4 #AUX_CFLAGS= -DSUNOS4 # For Solaris 2. #AUX_CFLAGS= -DSOLARIS2 #AUX_LIBS= -lsocket -lnsl # For SGI IRIX. Use the AUX_LIBS line if you're using NIS and want # user-supported directories #AUX_CFLAGS= -DIRIX #AUX_LIBS= -lsun # For HP-UX n.b. if you use the paid-for HP CC compiler, use flag -Ae #AUX_CFLAGS= -DHPUX # For AIX #AUX_CFLAGS= -DAIX -U__STR__ # For Ultrix #AUX_CFLAGS= -DULTRIX # For DEC OSF/1 #AUX_CFLAGS= -DOSF1 # For NeXT #AUX_CFLAGS= -DNEXT # For Sequent #AUX_CFLAGS= -DSEQUENT # For Linux -m486 ONLY IF YOU HAVE 486 BINARY SUPPORT IN KERNEL #AUX_CFLAGS= -DLINUX # For A/UX #AUX_CFLAGS= -DAUX -D_POSIX_SOURCE #AUX_LIBS= -lposix -lbsd -s # For SCO ODT 3 # libcrypt_i available from sosco.sco.com, files /SLS/lng225b.Z and # /SLS/lng225b.ltr.Z # the -Oe option causes cc to die compiling mod_imap (using 3.0.0a of the dev sys) #CFLAGS= -Oacgiltz #AUX_CFLAGS= -DSCO #AUX_LIBS= -lPW -lsocket -lmalloc -lcrypt_i # For SCO OpenServer Release 5 # -K noinline is needed to work around an optimiser bug which appears in # http_bprintf.c #AUX_CFLAGS= -DSCO5 #AUX_LIBS=-lsocket -lmalloc -lprot #BROKEN_BPRINTF_FLAGS=-K noinline # For SVR4 # Some SVR4 implementations will require SO_LINGER option to be set in order # to guarantee buffer flushes. Dell, Esix, and UnixWare are a few of these. # Use -DNEED_LINGER in addition to other AUX_CFLAGS for these. #AUX_CFLAGS= -DSVR4 #AUX_LIBS= -lsocket -lnsl -lc # For UnixWare 2.x, no longer just SVR4 (sigh) - use cc, not gcc # AUX_LIBS= -lsocket -lnsl -lcrypt # For Amdahl UTS 2.1 # -Xa enables ANSI mode, -eft is expanded types #AUX_CFLAGS= -Xa -eft -DUTS21 #AUX_LIBS= -lsocket -lbsd -la # For HP/Apollo Domain/OS #AUX_CFLAGS= -DAPOLLO # For NetBSD/FreeBSD/BSDI 2.x # -m486 only if you are running on Intel 486/586 #AUX_CFLAGS= -m486 # BSDI doesn't need -lcrypt #AUX_LIBS= -lcrypt # For QNX #AUX_CFLAGS= -DQNX #AUX_LFLAGS= -N 0x20000 # For LynxOS #AUX_CFLAGS= -DLYNXOS #EXTRA_LIBS=-lbsd -ldes -lc_p # For DG/UX 5.4 #AUX_CFLAGS= -DDGUX #AUX_LIBS= # For EMX OS/2 port #AUX_CFLAGS= -Zbsd-signals -Zbin-files #-DNO_KILLPG -DNEED_STRCASECMP -DNO_SETSID #-g #AUX_LIBS= -lsocket -llibufc -lgdbm -lbsd ########################################### # Module configuration # # Modules are listed in reverse priority order --- the ones that come # later can override the behavior of those that come earlier. This # can have visible effects; for instance, if UserDir followed Alias, # you couldn't alias out a particular user's home directory. # The configuration below is what we consider a decent default # configuration. If you want the functionality provided by a particular # module, remove the "#" sign at the beginning of the line. But remember, # the more modules you compile into the server, the larger the executable # is and the more memory it will take, so if you are unlikely to use the # functionality of a particular module you might wish to leave it out. ## Basic modules (i.e., generally useful stuff that works everyplace): ## You should probably not comment out any of these unless you know what it ## does and you know you won't need it. Module mime_module mod_mime.o Module access_module mod_access.o Module auth_module mod_auth.o Module negotiation_module mod_negotiation.o Module includes_module mod_include.o Module dir_module mod_dir.o Module cgi_module mod_cgi.o Module userdir_module mod_userdir.o Module alias_module mod_alias.o Module env_module mod_env.o Module common_log_module mod_log_common.o ## The asis module implemented ".asis" file types, which allow the embedding ## of HTTP headers at the beginning of the document. mod_imap handles internal ## imagemaps (no more cgi-bin/imagemap/!). mod_actions is used to specify ## CGI scripts which act as "handlers" for particular files, for example to ## automatically convert every GIF to another file type. Module asis_module mod_asis.o Module imap_module mod_imap.o Module action_module mod_actions.o ## Optional modules for NCSA user-agent/referer logging compatibility ## We recommend, however, that you migrate to the configurable logging ## module, below. # Module agent_log_module mod_log_agent.o # Module referer_log_module mod_log_referer.o ## This is a *replacement* for mod_log_common which supports a ## LogFormat directive which allows you to specify what goes into ## the TransferLog (if you want Referer, etc.) source code for docs. ## ## If you play with this, remember to drop the standard ## mod_log_common --- a server with both will work, but you'll get ## very confused trying to figure out what's going on... # Module config_log_module mod_log_config.o ## cern_meta mimicks the behavior of the CERN web server with regards to ## metainformation files. # Module cern_meta_module mod_cern_meta.o ## The status module allows the server to display current details about ## how well it is performing and what it is doing. Consider also enabling ## -DSTATUS (see the CFLAGS section near the start of the file) to allow ## full status information. Check conf/access.conf on how to enable this. # Module status_module mod_status.o ## The Info module displays configuration information for the server and ## all included modules. It's very useful for debugging. # Module info_module mod_info.o ## Optional authentication modules. ## ## The anon_auth module allows for anonymous-FTP-style username/ ## password authentication. # Module anon_auth_module mod_auth_anon.o ## db_auth and dbm_auth work with Berkeley DB files - make sure there ## is support for DBM files on your system. You may need to grab the GNU ## "gdbm" package if not. # Module db_auth_module mod_auth_db.o # Module dbm_auth_module mod_auth_dbm.o ## msql_auth checks against an MSQL database. You must have MSQL installed ## and an "msql.h" available for this to even compile. Additionally, ## you may need to add a couple entries to the CFLAGS line, like ## ## -lmsql -L/usr/local/lib -L/usr/local/Minerva/lib ## ## This depends on your installation of MSQL. # Module msql_auth_module mod_auth_msql.o ## "digest" implements HTTP Digest Authentication rather than the less ## secure Basic Auth used by the other modules. # Module digest_module mod_digest.o ## Outright experiments --- mod_dld defines commands which ## allows other modules to be loaded in at runtime, and mod_cookies ## uses Netscape cookies to automatically construct and log accurate ## click-trails from Netscape cookies, for Netscape-using clients who ## aren't coming in via proxy. # Module dld_module mod_dld.o # Module cookies_module mod_cookies.o ## Finally, the proxy module. It's not as complete as it could ## be yet, so use at your own risk. # Module proxy_module mod_proxy.o |
|