RC-HTTPD(8)RC-HTTPD(8)

NAME

rc-httpd – HTTP server

SYNOPSIS

rc-httpd/rc-httpd

DESCRIPTION

Rc-httpd serves the requested file or an index of files found under a website’s root directory, or, in the case of CGI, executes a specified CGI program.

CONFIGURATION

As all pieces of rc-httpd are shell scripts, configuration is achieved by setting variables and adding, removing or modifying commands in various files.

rc-httpd

rc_httpd_dir must be set to the root of the rc-httpd installation, the directory containing the rc-httpd script.

path must include rc_httpd_dir/handlers ahead of the base system’s path elements.

cgi_path is substituted for path when cgi scripts are run. (Be sure to set path back in rc-based cgi scripts.)

extra_headers is an optional list of strings to emit when sending http headers.

SERVER_PORT is the port HTTP is to be served on.

select-handler

PATH_INFO is the location relative to the website’s root directory of the file to be displayed. Typically, the location from the incoming request is honored.

FS_ROOT sets the root directory of the website.

NOINDEXFILE instructs the dir-index module not to look for index.html files, otherwise if an index.html file is found dir-index will exec serve-static to serve the file. At present there is no module to serve an index file but not a directory.

If you do not want directory indexing at all, replace static-or-index with serve-static, which will report 503 forbidden for directories.

Multiple virtual hosts may be configured by creating conditional statements that act upon the SERVER_NAME variable. Fine-grained control of specific request strings may be configured via a similar method acting upon the location and/or other variables.

EXAMPLES

The following examples demonstrate possible ways to configure select-handler.

Serve static files:

if(~ $SERVER_NAME 9front.org){
	PATH_INFO=$location
	FS_ROOT=/usr/sl/www/$SERVER_NAME
	exec static-or-index
}

CGI:

if(~ $SERVER_NAME *cat-v.org){
	PATH_INFO=$location
	FS_ROOT=/usr/sl/www/werc/sites/$SERVER_NAME
	exec static-or-cgi /usr/sl/www/werc/bin/werc.rc
}

Custom error message for a denied URL:

fn do_error{
	do_log $1
	echo 'HTTP/1.1 '^$1^$cr
	emit_extra_headers
	echo 'Content-type: text/html'^$cr
	echo $cr
	echo '<html>
<head>
<title>'^$1^'</title>
</head>
<body>
<h1>'^$1^'</h1>'
	echo $2
	echo '<p><i>rc-httpd at' $SERVER_NAME '</i>'
	echo '
	</body>
	</html>
	'
}
if(~ $location /v8.tar.bz2){
	do_error '27b/6'
	exit
}

STARTUP

Rc-httpd is run from a file in the directory scanned by listen(8), or called as an argument to aux/listen1. The program’s standard error may be captured to a log file:

exec /rc/bin/rc-httpd/rc-httpd >>[2]/sys/log/www

FILES

/rc/bin/rc-httpd/rc-httpd

 

/rc/bin/rc-httpd/select-handler

 

/rc/bin/rc-httpd/handlers/cgi

 

/rc/bin/rc-httpd/handlers/dir-index

 

/rc/bin/rc-httpd/handlers/error

 

/rc/bin/rc-httpd/handlers/redirect

 

/rc/bin/rc-httpd/handlers/serve-static

 

/rc/bin/rc-httpd/handlers/static-or-cgi

 

/rc/bin/rc-httpd/handlers/static-or-index

 

/rc/bin/service/tcp80

 

/sys/log/www

 

SOURCE

/rc/bin/rc-httpd

SEE ALSO

rc(1), listen(8)

HISTORY

Rc-httpd first appeared in 9front (February, 2013).