Basic Apache Configuration

From Zanecorpwiki

Jump to: navigation, search

Building

Always build Apache to use loadable (rather than statically linked) modules. There's no reason not to, and it's the only way to add module based functionality without taking down the server.

Key Global Configurations

  • ListenOn Declares an IP/port for Apache to bind to. Can be declared multiple times to bind to multiple ports (useful for port specific configurations, such as supporting SSL and non-SSL virtual servers on the same server process server). If you're running the server as a user (good idea for security), then you must bind to a high port above 1024 (see Running Apache as a User).
  • DocumentRoot Where the server root dir starts. In many cases on production systems, this value isn't critical as the actual serving will be done through virtual servers, but for development servers, or very simple configurations, you can set the document root and go.

Directory/Location Specific Configurations

Don't use htaccess. Htaccess files (.htaccess) can be placed in directories and provide directory specific configuration overrides. The htaccess method is off by default and can be considered a security risk, but the biggest problem is htaccess spreads out the configuration randomly around a site. You're much better off using location specific configurations.

There are two basic methods to configure parts of a site (or sites): the Location and the Directory directives. Location directives refer to the path portion of URLs while Directory directives refer to the directory on the filesysem of the underlying host. Either approach may work, or one may make more sense depending on how other configuration is done. There is also a 'LocationMatch' directive which matches path information against a regular expression. This can be useful for, say, barring access to all 'include' directories to hide configuration and libraries.

The best thing about these directives is that they are cross site. A LocationMatch directive, like the one above, in the global portion of the configuration file would protect all include directories in all sites served by all virtual servers.

Personal tools