Home   Notes   Contact Me

Apache

Local

External


Setup to a simple config


403 Forbidden


Configuring a New Install

  1. Run the windows installer and take the defaults, except set the name of the server
  2. Disable directory listing see: Directory Access

Removing a file and making it known

This uses mod_alias

Use the command Redirect gone path-from-top-of-website

Example: Redirect gone /notes/everquest.html


Redirecting based on Hostname to a Path

From http://www.onlamp.com/pub/a/apache/2003/12/23/apache_ckbk.html

Support virutal hosts by remapping a the hostname to a directory.

Use mod_rewrite

RewriteEngine on
RewriteCond   %{HTTP_HOST}     ^(www\.)?([^.]+)\.com$
RewriteRule   ^(.*)$   /home/%2$1

Directory Access

Note: There must be no spaces between the allow deny and the comma

Example settings

<Directory />
	Order deny,allow
	deny from all
#the following line disables getting directory listings:
	Options -Indexes
</Directory>

<Directory /usr/local/apache/vhosts/cousineddie>
	Order allow,deny
	Allow from all
</Directory>

Modules

NeedModuleDescription
Very Importantmod_accessAllows and Deny's access to items (such as .htaccess and .htpasswd)
Optionalmod_actionsThis module provides for executing CGI scripts based on media type or request method.
Optionalmod_asisAllows sending of files that contain their own http header information
Optionalmod_authUser authentication using text files
Optionalmod_autoindexMakes the directory listing pages if they are allowed.
Optionalmod_cgiRuns cgi scripts
Very Importantmod_dirAddes a trailing '/' if the URL is a directories that don't have one.
Lets you pick what the defaut file to load in a directory is.
Optionalmod_envModifies the environment which is passed to CGI scripts and SSI pages
Optionalmod_imapServerside image map support.
Optionalmod_includeServer side include support.
Junkmod_isapiAllows some Microsoft ISAPI modules to be used.
Required?mod_mimeAssociates the requested filename's extensions with the file's behavior (handlers and filters) and content (mime-type, language, character set and encoding)
MORE TO ADD

Log Piping

http://builder.com.com/5100-6372_14-5092424.html

Redirecting page requests with ip address in the URL to a Domain in the URL

<virtualhost *:80>
        ServerName 66.56.82.97
        RedirectMatch permanent (.*) http://www.exogenesis.org$1
</virtualhost>

SEARCH, filtering this out of the access log

From the best I can tell, this is some sort of attack on IIS
SEARCH /\x90\x02\xb1\x02...
It is a very long line and mucks up looking at the access.log. Here is how to keep it out of the log:

This works, but limits logging to only GETs and POSTs

I am still working on this, but it looks like mod_rewrite is the way to go.

Log Rotating

Here is how to turn on automatic log rotating. (add the following to httpd.conf)

TransferLog usage

TransferLog "|rotcmd"

rotcmd is the command to be used to rotate the logs. Since Apache comes with a log rotate command, its description follows.

rotatelogs usage

rotatelogs is part of the Apache distrobution

rotatelogs logpath rotint [ offset ]

logpath is the path to the logfile to rotate.
rotint is the rotation interval time in seconds.
offest number of minutes to offest from UTC (defaults to zero). For UTC -5 hours use -300.

Example


Redirecting

RedirectPermanent

Redirect

I have a friends domain pointing to my server, but his web pages are stored at an ISP. I figured out how to get his URL to load his page at the ISP. I added the following to my httpd.conf file:

(Note that there is no file with the name tigerofdoom.html on my server)

<VirtualHost *:80>
        DocumentRoot "C:/Program Files/Apache Group/Apache2/htdocs"
        ServerName www.tigerofdoom.com
        DirectoryIndex /tigerofdoom.html
</VirtualHost>

Redirect /tigerofdoom.html http://home.comcast.net/~tigerofdoom/

Password Protecting a Directory

  1. Make a password file using Apache's htpasswd.exe (find it in the Apache/bin directory)
  2. Put it where ever you want it, but not in the htdocs path (big security risk if you do)
  3. Add something like the following to the httpd.conf file

Note: You can do this at the end of the conf file and have it work for all virtual hosted websites


Virtual Host (serve different pages based on address)

Note: If you use VirtualHosts, then there is _NO_ main default host. All hosting is done through VirtualHosts, so you must make your default settings occur in a VirtualHost block.

  1. The first VirtualHost block is the default block that gets used if a match does not happen with any of the VirtualHost blocks.
  2. Turn on Virtual host ability NameVirtualHost *:80
    You can optionally use an IP address (useful if machine has multiple IP address) and you can specify another port if you want to
  3. Add VirtualHost blocks. Make sure the argument to VirtualHost matches the value of NameVirtualHost.
  4. See example below:

Default Initial Page

To change it: DirectoryIndex newDefaultPage.html

You can also add alternate defaults by appending more values:
DirectoryIndex index.html index.php


Command Line

Usage: apache [-D name] [-d directory] [-f file] [-n service]
              [-C "directive"] [-c "directive"] [-k signal]
              [-v] [-V] [-h] [-l] [-L] [-S] [-t] [-T]
              
  -D name          : define a name for use in  directives
  -d directory     : specify an alternate initial ServerRoot
  -f file          : specify an alternate ServerConfigFile
  -C "directive"   : process directive before reading config files
  -c "directive"   : process directive after  reading config files
  -v               : show version number
  -V               : show compile settings
  -h               : list available command line options (this page)
  -l               : list compiled-in modules
  -L               : list available configuration directives
  -S               : show parsed settings (currently only vhost settings)
  -t               : run syntax check for config files (with docroot check)
  -T               : run syntax check for config files (without docroot check)
  -n name          : name the Apache service for -k options below;
  -k stop|shutdown : tell running Apache to shutdown
  -k restart       : tell running Apache to do a graceful restart
  -k start         : tell Apache to start
  -k install   | -i: install an Apache service
  -k config        : reconfigure an installed Apache service
  -k uninstall | -u: uninstall an Apache service

cgi from windows .bat files


@echo off
echo "content-type: text/plain"
echo.
echo "Have a nice day"

NOTE: The trick is that echo. prints just a carrage return

Dumb IE problem

IE will sometimes think you are trying to download instead of running a .bat file here is a trick to make it not try that. Tack a path onto the end of the URL like this http://localhost/cgi-bin/test.bat/fakepath this passes fakepath as the environment setting PATH_INFO to the bat file


Directory Browsing

You set or disable this in a <directory> block, the Indexes command is cases sensitive.

Note: place this at the end of httpd.conf to make it work right. I need to figure out where the highest place it can go is.

#too allow browsing
<directory "C:/Program Files/Apache Group/Apache2/htdocs">
	Options +Indexes
</directory>

#to disallow browsing
<directory "C:/Program Files/Apache Group/Apache2/htdocs">
	Options -Indexes
</directory>

Aliases

Used to map arbitraray directorys on the system to specific URLS. Put something like the following in the httpd.conf file.