Custom Error Page returns status 200

I was recently playing with Google’s webmaster tools and ran into a problem with my custom error page. Although I have had it set up for some time, it was apparently incorrectly configured. Google complained ‘We’ve detected that your 404 file (file
not found) error page returns a status of 200 (Success) in the header. ” which means that the page was found and they’re not happy.

In order to troubleshoot this, I connected to my web server using telnet. This enabled me to see the exact data that Apache is delivering in reply to the request. This is what you need to do

  1. Open a Command prompt window (run cmd.exe on a PC)
  2. Connect to the web server (Apache) using telnet. If your web server does not run on port 80, then use the correct value. telnet mydomain.com 80
  3. Ask for the header of a non existent page by typing HEAD invalidpage.html HTTP/1.0. Although the cursor moves, NO TEXT WILL APPEAR ON THE SCREEN.
  4. Press the Enter key twice and wait for a reply

The reply you get should look something like this

HTTP/1.1 404 Not Found
Date: Fri, 30 Mar 2007 11:30:22 GMT
Server: Apache/2.0.52 (Red Hat)
Last-Modified: Fri, 30 Mar 2007 09:56:45 GMT
ETag: "13148ae-4fd-e39fb140;741a7f80"
Accept-Ranges: bytes
Content-Length: 1277
Connection: close
Content-Type: text/html

Connection to host lost.


When I tested my site, I found that it was responding

HTTP/1.1 302 Found
Date: Fri, 30 Mar 2007 11:33:22 GMT
Server: Apache/1.3.27 (Unix) (Red-Hat/Linux) mod_ssl/2.8.12 OpenSSL/0.9.6b PHP/4.4.2
Location: http://xxx.xxx.xxx.xxx/404.html
Connection: close
Content-Type: text/html; charset=iso-8859-1

Connection to host lost.

So my server was returning a status code of 302 which is a temporary redirect. When Google followed this to the new location, it received the 200 status code as the ultimate file exists. I tried adding the line

<meta http-equiv="Status" content="404 Condition Intercepted" />

in the head section of my error file as suggested on another site, but it made no difference. The real problem was that I had failed to notice the comments in the Apache manual

Note that when you specify an ErrorDocument that points to a remote URL (ie. anything with a method such as http in front of it), Apache will send a redirect to the client to tell it where to find the document, even if the document ends up being on the same server. This has several implications, the most important being that the client will not receive the original error status code, but instead will receive a redirect status code. This in turn can confuse web robots and other clients which try to determine if a URL is valid using the status code.

I wanted to use the same error page for multiple domains hosted on my VPS and so had hardcoded the IP Address into the URL. The line in my Apache configuration file read ErrorDocument 404 http://xxx.xxx.xxx.xxx/404.html. I therefore changed it to ErrorDocument 404 /errorp/404.html and created an alias for /errorp/ Alias /errorp/ “/path/to/custom_errors/”. My custom error page now responds correctly :)


HTTP/1.1 404 Not Found
Date: Fri, 30 Mar 2007 12:43:22 GMT
Server: Apache/1.3.27 (Unix) (Red-Hat/Linux) mod_gzip/1.3.26.1a mod_ssl/2.8.12
OpenSSL/0.9.6b PHP/4.4.2
Last-Modified: Fri, 30 Mar 2007 12:12:48 GMT
ETag: "2c6439c-261c-460d8b60;46a7f31a"
Accept-Ranges: bytes
Content-Length: 9756
Connection: close
Content-Type: text/html


If you have to use http: in your Custom Error Page's definition, then you are better off using a redirect in a local file. This will preserve the error status code. Your local error file should look something like this

<HTML><HEAD>
<META http-equiv="refresh" content="0; URL=http://www.example.com">
</HEAD>
<div style="visibility:hidden">
;Lets insert some random text here in order to keep Microsoft Internet
;Explorer happy. In their wisdom, Microsoft have decided that any custom
;error page with less than five hundred and twelve characters of text
;in it will be totally ignored and they will display their Friendly HTTP Error
;message instead. This is detailed in knowledge base article Q294807
;at http://support.microsoft.com/default.aspx?scid=kb;en-us;Q294807
;Well, I think that that is enough from me for now or maybe I should
;just type a little bit more to make sure that I have typed enough...
</div></BODY></HTML>

Gnulib

gnulib is a collection of approximately 590 routines which allow programs to be built on a cross platform basis. These are files intended to be shared at the source level rather than being a library meant to be installed and linked against so, unlike most projects, Gnulib does not normally generate a source tarball distribution; instead, developers should just grab modules directly from the repository. (The full list of modules and their description can be found here.) If you are missing one of the modules, you will get an error along the lines of

./configure: gl_XALLOC: command not found

when running ./configure

There are several ways to get hold of a copy of the repository:

  1. If you have git installed, then use the command git clone git://git.sv.gnu.org/gnulib
  2. If you prefer the CVS-like frontend of ‘cogitocg clone git://git.sv.gnu.org/gnulib
  3. If you have tightly limited disk space and a fast network connection, then CVS checkouts are also supported:
    $ cvs -d :pserver:anoncvs@cvs.gnu.org:/cvsroot/gnulib login
    (Just hit Enter or Return when prompted for a password)
    $ cvs -d :pserver:anoncvs@cvs.gnu.org:/cvsroot/gnulib checkout gnulib
  4. Download a snapshot from GNU’s Savannah server using wget

Since Westhost’s platform has none of git, cogito or cvs installed by default, I used the final option to obtain a copy of gnulib.git-HEAD.tar.gz
In order to use gnulib, you will need to download the gnulib-tool script and then use this to install the required modules. Don’t forget that you will need to give gnulib-tool execution rights (chmod u+x gnulib-tool).

Add details on installing module here

gnulib comprises the following routines and macros:
absolute-header, acl, alloca, alloca-opt, alloca-opt-tests, allocsa, allocsa-tests, announce-gen, arcfour, arcfour-tests, arctwo, arctwo-tests, argmatch, argmatch-tests, argp, argp-tests, argz, arpa_inet, arpa_inet-tests, array-list, array-list-tests, array-oset, array-oset-tests, assert, atexit, atexit-tests, autobuild, avltreehash-list, avltreehash-list-tests, avltree-list, avltree-list-tests, avltree-oset, avltree-oset-tests, backupfile, base64, bcopy, binary-io, binary-io-tests, bison-i18n, byteswap, byteswap-tests, calloc, canon-host, canonicalize, canonicalize-lgpl, canonicalize-lgpl-tests, carray-list, carray-list-tests, c-ctype, c-ctype-tests, chdir-long, chdir-safer, check-version, chown, classpath, clean-temp, clock-time, cloexec, closein, closein-tests, closeout, close-stream, config-h, configmake, copy-file, crc, crc-tests, crypto, csharpcomp, csharpcomp-script, csharpexec, csharpexec-script, c-stack, c-strcase, c-strcaseeq, c-strcasestr, c-strcasestr-tests, c-strcase-tests, c-strstr, c-strstr-tests, c-strtod, c-strtold, cycle-check, des, des-tests, dev-ino, diacrit, d-ino, dirfd, dirname, dirname-tests, double-slash-root, d-type, dummy, dup2, eealloc, elisp-comp, error, euidaccess, exclude, execute, exit, exitfail, extensions, fatal-signal, fbufmode, fbufmode-tests, fchdir, fcntl, fcntl-safer, fcntl-tests, fdl, fflush, fflush-tests, fileblocks, filemode, filename, filenamecat, file-type, findprog, flexmember, float, fnmatch, fnmatch-gnu, fnmatch-posix, fopen-safer, fpending, fpieee, fprintf-posix, fprintf-posix-tests, fprintftime, fpucw, fpurge, fpurge-tests, freadable, freadable-tests, freading, freading-tests, free, frexp, frexpl, frexpl-nolibm, frexpl-nolibm-tests, frexpl-tests, frexp-tests, fseek, fseeko, fseeko-tests, fseek-tests, fseterr, fseterr-tests, fsusage, ftell, ftello, ftello-tests, ftell-tests, ftruncate, fts, fts-lgpl, full-read, full-write, fwritable, fwritable-tests, fwriteerror, fwriting, fwriting-tests, gc, gc-arcfour, gc-arcfour-tests, gc-arctwo, gc-arctwo-tests, gcd, gc-des, gc-des-tests, gc-hmac-md5, gc-hmac-md5-tests, gc-hmac-sha1, gc-hmac-sha1-tests, gc-md2, gc-md2-tests, gc-md4, gc-md4-tests, gc-md5, gc-md5-tests, gc-pbkdf2-sha1, gc-pbkdf2-sha1-tests, gc-random, gc-rijndael, gc-rijndael-tests, gc-sha1, gc-sha1-tests, gc-tests, gendocs, getaddrinfo, getaddrinfo-tests, getcwd, getdate, getdelim, getdomainname, getgroups, gethostname, gethrxtime, getline, getloadavg, getlogin_r, getndelim2, getnline, getopt, getpagesize, getpass, getpass-gnu, getsubopt, gettext, gettext-h, gettime, gettimeofday, gettimeofday-tests, getugroups, getusershell, glob, gnupload, gpl, group-member, hard-locale, hash, hash-pjw, havelib, hmac-md5, hmac-md5-tests, hmac-sha1, hmac-sha1-tests, host-os, human, iconv, iconv_open, iconvme, iconv-tests, idcache, imaxabs, imaxdiv, inet_ntop, inet_pton, inline, intprops, inttostr, inttypes, inttypes-tests, i-ring, isapipe, isdir, isnanf-nolibm, isnanf-nolibm-tests, isnanl, isnanl-nolibm, isnanl-nolibm-tests, isnanl-tests, isnan-nolibm, isnan-nolibm-tests, javacomp, javacomp-script, javaexec, javaexec-script, javaversion, lchmod, lchown, ldd, ldexpl, ldexpl-tests, lgpl, lib-ignore, linebreak, linebuffer, linkedhash-list, linkedhash-list-tests, linked-list, linked-list-tests, link-follow, link-warning, list, localcharset, locale, locale-tests, lock, lock-tests, long-options, lseek, lseek-tests, lstat, maintainer-makefile, malloc, math, mathl, math-tests, mbchar, mbfile, mbiter, mbscasecmp, mbscasecmp-tests, mbscasestr, mbscasestr-tests, mbschr, mbschr-tests, mbscspn, mbscspn-tests, mbslen, mbsncasecmp, mbsncasecmp-tests, mbspbrk, mbspbrk-tests, mbspcasecmp, mbspcasecmp-tests, mbsrchr, mbsrchr-tests, mbssep, mbsspn, mbsspn-tests, mbsstr, mbsstr-tests, mbstok_r, mbswidth, mbuiter, md2, md2-tests, md4, md4-tests, md5, md5-tests, memcasecmp, memchr, memcmp, memcoll, memcpy, memmem, memmove, mempcpy, memrchr, memset, memxor, minmax, mkancesdirs, mkdir, mkdir-p, mkdtemp, mkstemp, mktime, modechange, mountlist, mpsort, nanosleep, netinet_in, netinet_in-tests, no-c++, obstack, openat, openat-die, openmp, oset, pagealign_alloc, pathmax, pathname, perl, physmem, phystemp, pipe, poll, posixtm, posixver, printf-frexp, printf-frexpl, printf-frexpl-tests, printf-frexp-tests, printf-posix, printf-posix-tests, printf-safe, progname, putenv, quote, quotearg, raise, rbtreehash-list, rbtreehash-list-tests, rbtree-list, rbtree-list-tests, rbtree-oset, rbtree-oset-tests, read-file, read-file-tests, readline, readlink, readtokens, readtokens0, readutmp, realloc, regex, regexprops-generic, relocatable, relocatable-lib, relocatable-lib-lgpl, relocatable-prog, relocatable-prog-wrapper, relocatable-script, rename, rename-dest-slash, rijndael, rijndael-tests, rmdir, rmdir-errno, rpmatch, safe-read, safe-write, same, same-inode, save-cwd, savedir, savewd, search, search-tests, setenv, settime, sha1, sh-quote, sig2str, signal, signbit, signbit-tests, sigprocmask, size_max, sleep, sleep-tests, snprintf, snprintf-posix, snprintf-posix-tests, snprintf-tests, socklen, sprintf-posix, sprintf-posix-tests, ssize_t, stat-macros, stat-time, stat-time-tests, stdarg, stdbool, stdbool-tests, stdint, stdint-tests, stdio, stdio-tests, stdlib, stdlib-safer, stdlib-tests, stpcpy, stpncpy, strcase, strcasestr, strcasestr-tests, strchrnul, strcspn, strdup, streq, strerror, strftime, striconv, striconveh, striconveha, striconveha-tests, striconveh-tests, striconv-tests, string, string-tests, strndup, strnlen, strnlen1, strpbrk, strptime, strsep, strtod, strtoimax, strtok_r, strtol, strtoll, strtoul, strtoull, strtoumax, strverscmp, sublist, sys_select, sys_select-tests, sys_socket, sys_socket-tests, sys_stat, sys_stat-tests, sys_time, sys_time-tests, sysexits, sysexits-tests, tempname, time, time_r, timegm, timespec, time-tests, tls, tls-tests, tmpdir, tmpfile, tmpfile-safer, tree | history, tree | history, tree | history, trim, tsearch, tsearch-tests, tzset, ucs4-utf16, ucs4-utf8, unicodeio, uniconv, unistd, unistd-safer, unistd-tests, unistr, unitypes, unlink-busy, unlinkdir, unlocked-io, uptime, userspec, utf16-ucs4, utf16-ucs4-unsafe, utf8-ucs4, utf8-ucs4-unsafe, utime, utimecmp, utimens, vararrays, vasnprintf, vasnprintf-posix, vasnprintf-posix-tests, vasnprintf-tests, vasprintf, vasprintf-posix, vasprintf-posix-tests, vasprintf-tests, verify, verror, version-etc, version-etc-fsf, vfprintf-posix, vfprintf-posix-tests, visibility, vprintf-posix, vprintf-posix-tests, vsnprintf, vsnprintf-posix, vsnprintf-posix-tests, vsnprintf-tests, vsprintf-posix, vsprintf-posix-tests, wait-process, wchar, wchar-tests, wctype, wctype-tests, wcwidth, winsz-ioctl, winsz-termios, write-any-file, xalloc, xalloc-die, xallocsa, xgetcwd, xgetdomainname, xgethostname, xmemcoll, xnanosleep, xreadlink, xreadlink-with-size, xsetenv, xsize, xstriconv, xstrndup, xstrtod, xstrtoimax, xstrtol, xstrtold, xstrtoumax, xvasprintf, xvasprintf-tests, yesno

m4 Auto Configure macros:
AC_C_FLEXIBLE_ARRAY_MEMBER, AC_C_VARARRAYS, AC_CHECK_FUNCS_ONCE([stpcpy]), AC_CHECK_FUNCS_ONCE([strdup]), AC_CONFIG_FILES([csharpcomp.sh:build-aux/csharpcomp.sh.in]), AC_CONFIG_FILES([csharpexec.sh:build-aux/csharpexec.sh.in]), AC_CONFIG_FILES([javacomp.sh:build-aux/javacomp.sh.in]), AC_CONFIG_FILES([javaexec.sh:build-aux/javaexec.sh.in]), AC_CONFIG_FILES([ldd.sh:build-aux/ldd.sh.in]), AC_DEFINE([SIGNAL_SAFE_LIST], [1], [Define if lists must be signal-safe.]), AC_FUNC_ACL, AC_FUNC_CALLOC, AC_FUNC_CANONICALIZE_FILE_NAME, AC_FUNC_MALLOC, AC_FUNC_OBSTACK, AC_FUNC_REALLOC, AC_OPENMP, AC_PROG_MKDIR_P, AC_REPLACE_FUNCS(bcopy), AC_REPLACE_FUNCS(raise), AC_REQUIRE([AC_C_BIGENDIAN]), AC_REQUIRE([gl_RELOCATABLE_NOP]), AC_REQUIRE([gt_CSHARPCOMP]), AC_SUBST([LIBINTL]), AC_SUBST([LTLIBINTL]), AC_SUBST_FILE([relocatable_sh])

gl_AC_FUNC_LINK_FOLLOWS_SYMLINK, gl_ALLOCSA, gl_ARCFOUR, gl_ARCTWO, gl_ARGMATCH, gl_ARGP, gl_ASSERT, gl_BACKUPFILE, gl_BYTESWAP, gl_C_STACK, gl_C_STRTOD, gl_C_STRTOLD, gl_CANON_HOST, gl_CANONICALIZE_LGPL, gl_CANONICALIZE_LGPL_SEPARATE, gl_CHDIR_SAFER, gl_CHECK_TYPE_STRUCT_DIRENT_D_INO, gl_CHECK_TYPE_STRUCT_DIRENT_D_TYPE, gl_CHECK_VERSION, gl_CLOCK_TIME, gl_CLOEXEC, gl_CLOSE_STREAM, gl_CLOSEIN, gl_CLOSEOUT, gl_CONFIG_H, gl_COPY_FILE, gl_CRC, gl_CYCLE_CHECK, gl_DES, gl_DIRNAME, gl_DOUBLE_SLASH_ROOT, gl_EEALLOC, gl_ERROR, gl_EXCLUDE, gl_EXECUTE, gl_EXITFAIL, gl_FATAL_SIGNAL, gl_FCNTL_H, gl_FCNTL_SAFER, gl_FILE_NAME_CONCAT, gl_FILE_TYPE, gl_FILEBLOCKS, gl_FILEMODE, gl_FINDPROG, gl_FLOAT_H, gl_FOPEN_SAFER, gl_FPRINTFTIME, gl_FSUSAGE, gl_FUNC_ALLOCA, gl_FUNC_ARGZ, gl_FUNC_ATEXIT, gl_FUNC_BASE64, gl_FUNC_CHDIR_LONG, gl_FUNC_CHOWN, gl_FUNC_DIRFD, gl_FUNC_DUP2, gl_FUNC_EUIDACCESS, gl_FUNC_FBUFMODE, gl_FUNC_FCHDIR, gl_FUNC_FFLUSH, gl_FUNC_FNMATCH_GNU, gl_FUNC_FNMATCH_POSIX, gl_FUNC_FPENDING, gl_FUNC_FPRINTF_POSIX, gl_FUNC_FPURGE, gl_FUNC_FREADABLE, gl_FUNC_FREADING, gl_FUNC_FREE, gl_FUNC_FREXP, gl_FUNC_FREXPL, gl_FUNC_FREXPL_NO_LIBM, gl_FUNC_FSEEK, gl_FUNC_FSEEKO, gl_FUNC_FTELL, gl_FUNC_FTELLO, gl_FUNC_FTRUNCATE, gl_FUNC_FTS, gl_FUNC_FTS_LGPL, gl_FUNC_FWRITABLE, gl_FUNC_FWRITING, gl_FUNC_GEN_TEMPNAME, gl_FUNC_GETCWD, gl_FUNC_GETDELIM, gl_FUNC_GETDOMAINNAME, gl_FUNC_GETGROUPS, gl_FUNC_GETHOSTNAME, gl_FUNC_GETLINE, gl_FUNC_GETPASS, gl_FUNC_GETPASS_GNU, gl_FUNC_GETSUBOPT, gl_FUNC_GETTIMEOFDAY, gl_FUNC_GETUSERSHELL, gl_FUNC_GLIBC_UNLOCKED_IO, gl_FUNC_GNU_STRFTIME, gl_FUNC_GROUP_MEMBER, gl_FUNC_ICONV_OPEN, gl_FUNC_IMAXABS, gl_FUNC_IMAXDIV, gl_FUNC_ISNAN_NO_LIBM, gl_FUNC_ISNANF_NO_LIBM, gl_FUNC_ISNANL, gl_FUNC_ISNANL_NO_LIBM, gl_FUNC_LCHMOD, gl_FUNC_LCHOWN, gl_FUNC_LDEXPL, gl_FUNC_LONG_DOUBLE_MATH, gl_FUNC_LSEEK, gl_FUNC_LSTAT, gl_FUNC_MBSCASECMP, gl_FUNC_MBSCASESTR, gl_FUNC_MBSCHR, gl_FUNC_MBSCSPN, gl_FUNC_MBSLEN, gl_FUNC_MBSNCASECMP, gl_FUNC_MBSPBRK, gl_FUNC_MBSPCASECMP, gl_FUNC_MBSRCHR, gl_FUNC_MBSSEP, gl_FUNC_MBSSPN, gl_FUNC_MBSSTR, gl_FUNC_MBSTOK_R, gl_FUNC_MEMCHR, gl_FUNC_MEMCMP, gl_FUNC_MEMCPY, gl_FUNC_MEMMEM, gl_FUNC_MEMMOVE, gl_FUNC_MEMPCPY, gl_FUNC_MEMRCHR, gl_FUNC_MEMSET, gl_FUNC_MKDIR_TRAILING_SLASH, gl_FUNC_MKSTEMP, gl_FUNC_MKTIME, gl_FUNC_NANOSLEEP, gl_FUNC_OPENAT, gl_FUNC_POLL, gl_FUNC_PRINTF_FREXP, gl_FUNC_PRINTF_FREXPL, gl_FUNC_PRINTF_POSIX, gl_FUNC_PUTENV, gl_FUNC_READ_FILE, gl_FUNC_READLINE, gl_FUNC_READLINK, gl_FUNC_READLINK_SEPARATE, gl_FUNC_RENAME, gl_FUNC_RENAME_TRAILING_DEST_SLASH, gl_FUNC_RMDIR, gl_FUNC_RMDIR_NOTEMPTY, gl_FUNC_RPMATCH, gl_FUNC_SETENV, gl_FUNC_SETENV_SEPARATE, gl_FUNC_SIG2STR, gl_FUNC_SLEEP, gl_FUNC_SNPRINTF, gl_FUNC_SNPRINTF_POSIX, gl_FUNC_SPRINTF_POSIX, gl_FUNC_STPCPY, gl_FUNC_STPNCPY, gl_FUNC_STRCASESTR, gl_FUNC_STRCHRNUL, gl_FUNC_STRCSPN, gl_FUNC_STRDUP, gl_FUNC_STRERROR, gl_FUNC_STRERROR_SEPARATE, gl_FUNC_STRNDUP, gl_FUNC_STRNLEN, gl_FUNC_STRPBRK, gl_FUNC_STRPTIME, gl_FUNC_STRSEP, gl_FUNC_STRTOD, gl_FUNC_STRTOIMAX, gl_FUNC_STRTOK_R, gl_FUNC_STRTOL, gl_FUNC_STRTOLL, gl_FUNC_STRTOUL, gl_FUNC_STRTOULL, gl_FUNC_STRTOUMAX, gl_FUNC_STRVERSCMP, gl_FUNC_TIMEGM, gl_FUNC_TSEARCH, gl_FUNC_TZSET_CLOBBER, gl_FUNC_UNLINK_BUSY_TEXT, gl_FUNC_UNSETENV, gl_FUNC_UTIME, gl_FUNC_VASNPRINTF, gl_FUNC_VASNPRINTF_POSIX, gl_FUNC_VASPRINTF, gl_FUNC_VASPRINTF_POSIX, gl_FUNC_VFPRINTF_POSIX, gl_FUNC_VPRINTF_POSIX, gl_FUNC_VSNPRINTF, gl_FUNC_VSNPRINTF_POSIX, gl_FUNC_VSPRINTF_POSIX, gl_FUNC_WCWIDTH, gl_GC, gl_GC_ARCFOUR, gl_GC_ARCTWO, gl_GC_DES, gl_GC_HMAC_MD5, gl_GC_HMAC_SHA1, gl_GC_MD2, gl_GC_MD4, gl_GC_MD5, gl_GC_PBKDF2_SHA1, gl_GC_RANDOM, gl_GC_RIJNDAEL, gl_GC_SHA1, gl_GETADDRINFO, gl_GETDATE, gl_GETHRXTIME, gl_GETLOADAVG([$gl_source_base]), gl_GETLOGIN_R, gl_GETNDELIM2, gl_GETNLINE, gl_GETOPT, gl_GETPAGESIZE, gl_GETTIME, gl_GETUGROUPS, gl_GLOB, gl_HARD_LOCALE, gl_HASH, gl_HEADER_ARPA_INET, gl_HEADER_NETINET_IN, gl_HEADER_STRING_H, gl_HEADER_SYS_SELECT, gl_HEADER_SYS_SOCKET, gl_HEADER_SYS_STAT_H, gl_HEADER_SYS_TIME_H, gl_HEADER_TIME_H, gl_HEADER_TIOCGWINSZ_IN_TERMIOS_H, gl_HEADER_TIOCGWINSZ_NEEDS_SYS_IOCTL, gl_HMAC_MD5, gl_HMAC_SHA1, gl_HOST_OS, gl_HUMAN, gl_I_RING, gl_ICONV_H, gl_IDCACHE, gl_IGNORE_UNUSED_LIBRARIES, gl_INET_NTOP, gl_INET_PTON, gl_INLINE, gl_INTTOSTR, gl_INTTYPES_H, gl_INTTYPES_MODULE_INDICATOR([imaxabs]), gl_INTTYPES_MODULE_INDICATOR([imaxdiv]), gl_INTTYPES_MODULE_INDICATOR([strtoimax]), gl_INTTYPES_MODULE_INDICATOR([strtoumax]), gl_ISAPIPE, gl_ISDIR, gl_LDD, gl_libdeps=”$gl_libdeps $LIBGCRYPT”, gl_libdeps=”$gl_libdeps $LIBICONV”, gl_LINEBREAK, gl_LIST, gl_list.m4, gl_LOCALCHARSET, gl_LOCALE_H, gl_LOCK, gl_LONG_OPTIONS, gl_ltlibdeps=”$gl_ltlibdeps $LTLIBGCRYPT”, gl_ltlibdeps=”$gl_ltlibdeps $LTLIBICONV”, gl_MATH_H, gl_MATH_MODULE_INDICATOR([frexp]), gl_MATH_MODULE_INDICATOR([frexpl]), gl_MATH_MODULE_INDICATOR([ldexpl]), gl_MATH_MODULE_INDICATOR([signbit]), gl_MBCHAR, gl_MBFILE, gl_MBITER, gl_MBSWIDTH, gl_MD2, gl_MD4, gl_MD5, gl_MEMCASECMP, gl_MEMCOLL, gl_MEMXOR, gl_MINMAX, gl_MKANCESDIRS, gl_MKDIR_PARENTS, gl_MODECHANGE, gl_MODULE_INDICATOR([canonicalize]), gl_MODULE_INDICATOR([close-stream]), gl_MODULE_INDICATOR([fcntl-safer]), gl_MODULE_INDICATOR([fopen-safer]), gl_MODULE_INDICATOR([fts]), gl_MODULE_INDICATOR([fwriteerror]), gl_MODULE_INDICATOR([gc-arcfour]), gl_MODULE_INDICATOR([gc-arctwo]), gl_MODULE_INDICATOR([gc-des]), gl_MODULE_INDICATOR([gc-hmac-md5]), gl_MODULE_INDICATOR([gc-hmac-sha1]), gl_MODULE_INDICATOR([gc-md2]), gl_MODULE_INDICATOR([gc-md4]), gl_MODULE_INDICATOR([gc-md5]), gl_MODULE_INDICATOR([gc-random]), gl_MODULE_INDICATOR([gc-rijndael]), gl_MODULE_INDICATOR([gc-sha1]), gl_MODULE_INDICATOR([unistr/u16-mbtouc]), gl_MODULE_INDICATOR([unistr/u16-mbtoucr]), gl_MODULE_INDICATOR([unistr/u16-mbtouc-unsafe]), gl_MODULE_INDICATOR([unistr/u16-uctomb]), gl_MODULE_INDICATOR([unistr/u32-mbtouc]), gl_MODULE_INDICATOR([unistr/u32-mbtoucr]), gl_MODULE_INDICATOR([unistr/u32-mbtouc-unsafe]), gl_MODULE_INDICATOR([unistr/u32-uctomb]), gl_MODULE_INDICATOR([unistr/u8-mbtouc]), gl_MODULE_INDICATOR([unistr/u8-mbtoucr]), gl_MODULE_INDICATOR([unistr/u8-mbtouc-unsafe]), gl_MODULE_INDICATOR([unistr/u8-uctomb]), gl_MOUNTLIST, gl_MPSORT, gl_PAGEALIGN_ALLOC, gl_PATHMAX, gl_PERL, gl_PHYSMEM, gl_PIPE, gl_POSIXTM, gl_POSIXVER, gl_QUOTE, gl_QUOTEARG, gl_READTOKENS, gl_READUTMP, gl_REGEX, gl_RELOCATABLE([$gl_source_base]), gl_RELOCATABLE_LIBRARY, gl_RELOCATABLE_LIBRARY_SEPARATE, gl_RIJNDAEL, gl_SAFE_READ, gl_SAFE_WRITE, gl_SAME, gl_SAVE_CWD, gl_SAVEDIR, gl_SAVEWD, gl_SEARCH_H, gl_SEARCH_MODULE_INDICATOR([tsearch]), gl_SETTIME, gl_SHA1, gl_SIGNAL_H, gl_SIGNAL_MODULE_INDICATOR([sigprocmask]), gl_SIGNALBLOCKING, gl_SIGNBIT, gl_SIZE_MAX, gl_STAT_BIRTHTIME, gl_STAT_TIME, gl_STDARG_H, gl_STDINT_H, gl_STDIO_H, gl_STDIO_MODULE_INDICATOR([fflush]), gl_STDIO_MODULE_INDICATOR([fprintf-posix]), gl_STDIO_MODULE_INDICATOR([fseek]), gl_STDIO_MODULE_INDICATOR([fseeko]), gl_STDIO_MODULE_INDICATOR([ftell]), gl_STDIO_MODULE_INDICATOR([ftello]), gl_STDIO_MODULE_INDICATOR([printf-posix]), gl_STDIO_MODULE_INDICATOR([snprintf]), gl_STDIO_MODULE_INDICATOR([sprintf-posix]), gl_STDIO_MODULE_INDICATOR([vasprintf]), gl_STDIO_MODULE_INDICATOR([vfprintf-posix]), gl_STDIO_MODULE_INDICATOR([vprintf-posix]), gl_STDIO_MODULE_INDICATOR([vsnprintf]), gl_STDIO_MODULE_INDICATOR([vsprintf-posix]), gl_STDLIB_H, gl_STDLIB_MODULE_INDICATOR([getsubopt]), gl_STDLIB_MODULE_INDICATOR([mkdtemp]), gl_STDLIB_MODULE_INDICATOR([mkstemp]), gl_STDLIB_SAFER, gl_STRCASE, gl_STRING_MODULE_INDICATOR([mbscasecmp]), gl_STRING_MODULE_INDICATOR([mbscasestr]), gl_STRING_MODULE_INDICATOR([mbschr]), gl_STRING_MODULE_INDICATOR([mbscspn]), gl_STRING_MODULE_INDICATOR([mbslen]), gl_STRING_MODULE_INDICATOR([mbsncasecmp]), gl_STRING_MODULE_INDICATOR([mbspbrk]), gl_STRING_MODULE_INDICATOR([mbspcasecmp]), gl_STRING_MODULE_INDICATOR([mbsrchr]), gl_STRING_MODULE_INDICATOR([mbssep]), gl_STRING_MODULE_INDICATOR([mbsspn]), gl_STRING_MODULE_INDICATOR([mbsstr]), gl_STRING_MODULE_INDICATOR([mbstok_r]), gl_STRING_MODULE_INDICATOR([memmem]), gl_STRING_MODULE_INDICATOR([mempcpy]), gl_STRING_MODULE_INDICATOR([memrchr]), gl_STRING_MODULE_INDICATOR([stpcpy]), gl_STRING_MODULE_INDICATOR([stpncpy]), gl_STRING_MODULE_INDICATOR([strcasestr]), gl_STRING_MODULE_INDICATOR([strchrnul]), gl_STRING_MODULE_INDICATOR([strdup]), gl_STRING_MODULE_INDICATOR([strndup]), gl_STRING_MODULE_INDICATOR([strnlen]), gl_STRING_MODULE_INDICATOR([strpbrk]), gl_STRING_MODULE_INDICATOR([strsep]), gl_STRING_MODULE_INDICATOR([strtok_r]), gl_SYS_PROC_UPTIME, gl_SYSEXITS, gl_TIME_R, gl_TIMESPEC, gl_TLS, gl_TMPFILE, gl_TMPFILE_SAFER, gl_TYPE_SOCKLEN_T, gl_UNICODEIO, gl_UNISTD_H, gl_UNISTD_MODULE_INDICATOR([chown]), gl_UNISTD_MODULE_INDICATOR([dup2]), gl_UNISTD_MODULE_INDICATOR([fchdir]), gl_UNISTD_MODULE_INDICATOR([ftruncate]), gl_UNISTD_MODULE_INDICATOR([getcwd]), gl_UNISTD_MODULE_INDICATOR([getlogin_r]), gl_UNISTD_MODULE_INDICATOR([lseek]), gl_UNISTD_MODULE_INDICATOR([readlink]), gl_UNISTD_MODULE_INDICATOR([sleep]), gl_UNISTD_SAFER, gl_UNLINKDIR, gl_USERSPEC, gl_UTIMECMP, gl_UTIMENS, gl_VISIBILITY, gl_WAIT_PROCESS, gl_WCHAR_H, gl_WCTYPE_H, gl_WINSIZE_IN_PTEM, gl_WRITE_ANY_FILE, gl_XALLOC, gl_XGETCWD, gl_XNANOSLEEP, gl_XSIZE, gl_XSTRNDUP, gl_XSTRTOD, gl_XSTRTOL, gl_XSTRTOLD, gl_XVASPRINTF, gl_YESNO

Building GLib

Glib is available from GTK by FTP. At the time of writing, the current version is 2.12.12

Download the source code

  • Connect to your server using PuTTY or some other SSH client
  • Connect to GTK’s FTP server by typing the command ftp ftp.gtk.org
  • Login using the username anonymous and password anon@
  • Change to the directory where the source code is stored cd /pub/glib/2.12/
  • Change the mode to binary by entering the command binary
  • Download the file using the command get glib-2.12.12.tar.gz
  • Also download the md5 checksum to verify the veracity of your download get glib-2.12.12.tar.gz.md5
  • Close your FTP session by typing quit
  • Having downloaded the source code, extract the files into a new directory by entering the command gunzip -c glib-2.12.12.tar.gz|tar x

Install dependencies

We need to download and install the libiconv and gettext libraries before we can build GLib. Also, since we do not have root access at Westhost, we need to tell all Linux packages to install to a different directory other than /usr/local. We do this by specifying

./configure --prefix=/usr/mylocal
NOTE: Create the directory /usr/mylocal if it does not already exist

Library Command Download Location
libiconv wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.11.tar.gz
libiconv wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.11.tar.gz.sig
gettext ftp ftp://mirrors.usc.edu/pub/gnu/gettext/gettext-0.16.tar.gz
gettext ftp ftp://mirrors.usc.edu/pub/gnu/gettext/gettext-0.16.tar.gz.sig

libiconv and gettext depend on each other, so we need to build libiconv then gettext and the rebuild libiconv.

Build libiconv

wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.11.tar.gz
wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.11.tar.gz.sig
gunzip -c libiconv-1.11.tar.gz | tar x
cd libiconv-1.11
./configure --prefix=/usr/mylocal >log.config 2>err.config
Check err.config for errors
make >log.make 2>err.make
This will build with errors, so do not check err.make for errors
make install >log.install 2>err.install
cd ..

Build gettext

ftp mirrors.usc.edu
anonymous
anon@
cd pub/gnu/gettext
mode image
passive
get gettext-0.16.tar.gz
get gettext-0.16.tar.gz.sig
quit
gunzip -c gettext-0.16.tar.gz |tar x
cd gettext-0.16
./configure --prefix=/usr/mylocal >log.config 2>err.config
Check err.config for errors
make>log.make 2>err.make
Check err.make for errors
make install> log.install 2>err.install
Check err.install for errors

Rebuild libiconv

cd ../libiconv-1.11
make distclean
./configure --prefix=/usr/mylocal >log.config 2>err.config
Check err.config for errors
make>log.make 2>err.make
Check err.make for errors
make install> log.install 2>err.install
Check err.install for errors
libtool --dry-run --finish /usr/mylocal/lib
libtool --finish /usr/mylocal/lib
cd ..

Build the GLib library

  • Change into the new directory cd glib-2.12.12
  • Run autoconfigure to determine the build parameters ./configure –with-libiconv –prefix=/usr/mylocal >log.config 2>err.config
  • Check the err.config file for any errors
  • Build the library make >log.make 2>err.make
  • Check err.make for errors
  • Install the library make install >log.install 2>err.install

Errors we encountered

#error GNU libiconv not in use but included iconv.h is from libiconv

Added –with-libiconv to ./configure

warning: passing arg 2 of `g_async_queue_push’ discards qualifiers from pointer target type

This is only a warning and so can be ignored

mod-gzip – How To Download pages faster and Save Server Bandwidth

I recently ran these pages through a Web Optimiser and the speeds were not that impressive, so I have decided to implement mod_gzip. This will compress the textual portion of these pages so that they download quicker.

The procedure will NOT follow the familiar procedure for those who follow this site, so read on…

  • Download the source from Sourceforge.net using the command wget, for example wget http://easynews.dl.sourceforge.net/sourceforge/mod-gzip/mod_gzip-1.3.26.1a.tgz. Choose the mirror nearest to your server. If you are running Apache 2.0, then you will need to donload the module from here instead.
  • Unzip this file and extract the contents so that we can get on with the build gunzip -c mod_gzip-1.3.26.1a.tgz | tar x
  • Change into the source directory cd mod_gzip-1.3.26.1a.
  • The directions for building mod_gzip are included at the end of the ChangeLog file.

    There are two ways to build mod_gzip:

    1. statically compiled into Apache and
    2. a DSO-File for mod_so.

    The DSO-Version is much easier to build. Just type

    make APXS=/path/to/apxs
    make install APXS=/path/to/apxs
    /path/to/apachectl restart

    The apxs script is normaly located inside the bin directory of Apache.

    The path to APXS is /usr/local/apache/bin/apxs or /usr/sbin/apxs, so we will use the command
    make APXS=/usr/sbin/apxs >log.make 2>err.make
    NOTE:You will get an error complaining about ok_to_send being unused. This Warning can be safely ignored.
    mod_gzip.c: In function `mod_gzip_sendfile2':
    mod_gzip.c:5262: warning: unused variable `ok_to_send'

  • The final step of the build process is to install the module. This will copy the library to the relevant place and edit your httpd.conf file.
    make install APXS=/usr/sbin/apxs >log.install 2>err.install
    The installer inserted two lines into the httpd.conf file, which are commented out. However, it did not quite get it right on my system, so it is just as well that they are commented out! The lines read

    <IfDefine HAVE_FRONTPAGE_SPHERA>
    LoadModule frontpage_module modules/mod_frontpage_sphera.so
    #LoadModule gzip_module /usr/lib/apache/mod_gzip.so
    </IfDefine>

    and should have read


    <IfDefine HAVE_FRONTPAGE_SPHERA>
    LoadModule frontpage_module modules/mod_frontpage_sphera.so
    </IfDefine>
    <IfDefine HAVE_GZIP>
    LoadModule gzip_module /usr/lib/apache/mod_gzip.so
    </IfDefine>

    The variable HAVE_GZIP is automatically created by the start up process. The installer also made the same mistake with the AddModule directives which read
    <IfDefine HAVE_FRONTPAGE_SPHERA>
    AddModule mod_frontpage_sphera.c
    #AddModule mod_gzip.c
    </IfDefine>

    instead of

    <IfDefine HAVE_FRONTPAGE_SPHERA>
    AddModule mod_frontpage_sphera.c
    </IfDefine>
    <IfDefine HAVE_GZIP>
    AddModule mod_gzip.c
    </IfDefine>

  • There are still a couple of changes to make to the httpd.conf file according to Apache’s own website. The following needs to be added to the configuration file; I added it just after the AddModule (within the define block)
    mod_gzip_on Yes
    mod_gzip_can_negotiate Yes
    mod_gzip_dechunk Yes
    mod_gzip_minimum_file_size 600
    mod_gzip_maximum_file_size 0
    mod_gzip_maximum_inmem_size 100000
    mod_gzip_keep_workfiles No
    mod_gzip_temp_dir /usr/local/apache/gzip
    mod_gzip_item_include file \.html$
    mod_gzip_item_include file \.txt$
    mod_gzip_item_include file \.jsp$
    mod_gzip_item_include file \.php$
    mod_gzip_item_include file \.pl$
    mod_gzip_item_include mime ^text/.*
    mod_gzip_item_include mime ^application/x-httpd-php
    mod_gzip_item_include mime ^httpd/unix-directory$
    mod_gzip_item_include handler ^perl-script$
    mod_gzip_item_include handler ^server-status$
    mod_gzip_item_include handler ^server-info$
    mod_gzip_item_exclude file \.css$
    mod_gzip_item_exclude file \.js$
    mod_gzip_item_exclude mime ^image/.*

    Additional filetypes can be defined. For example, there is no need to compress PDF files as they are already compressed, so we could also add
    mod_gzip_item_exclude mime ^application/pdf$
  • You will also need to create the mod_gzip_temp_dir specified in httpd.conf. mkdir /usr/local/apache/gzip
  • Next restart Apache and check that everything is still working. If you get the error
    Syntax error on line xxx of /etc/httpd/conf/httpd.conf:
    Cannot add module via name 'mod_gzip.c': not in list of loaded modules
    then you forgot top remove the # from the LoadModule command or mod_glib.so is not in the correct directory.

Installing and Running Rsync

DRAFT POSTING

This post is very long, so I have broken it down into multiple pages.
Page 1 – Installing rsync daemon on your server
Page 2 – Installing rsync client on your PC
Page 3 – Scheduling rsync automatically
Page 4 – Errors I encountered and their solutions


Download and build rsync from source

  • Start a SSH session to your server
  • Download the source from samba wget http://samba.anu.edu.au/ftp/rsync/rsync-2.6.9.tar.gz
  • Extract the source code gunzip -c rsync-2.6.9.tar.gz | tar x
  • Change into the directory so that we can build the software cd rsync-2.6.9
  • You will need the GCC compiler installed if you have not already done so.
  • Run the auto configure script so that the server can work out if everything necessary is present ./configure –prefix=/usr/mylocal –with-included-popt >log.config 2>err.config
  • Check that no errors were logged by the configure script less err.config
  • Build the application make >log.make 2>err.make
  • Check that no errors were logged during the build process less err.make
  • Install the application make install >log.install 2>err.install
  • Check that no errors were logged during the installation less err.install

Configure the rsync daemon

We cannot use the default port (873) on Westhost as this is used by Westhost’s own application for nightly backups. Nor can we use ports below 1024 as these require us to run as root. However, ports 8730-8732 are unassigned by IANA (Internet Assigned Numbers Authority), so we can use any of these.

  • Create a directory for your configuration files. mkdir /etc/rsyncd
  • Create a new configuration file pico /etc/rsyncd.conf. The configuration file consists of a general configuration section which applies to every module and one (or more) modules. Each module starts with its name in square brackets, for example [rsyncd_module].
    This sample configuration file will allow upto 3 rsync clients to read the contents of /ftp/pub/rsync PROVIDED that they authenticate themselves by providing the correct credentials AND their IP Address is in the range specified by hosts allow. The connection will close down after 5 minutes (300 seconds) of inactivity.

    #Global definitions
    #Message of the Day
    motd file = /etc/rsyncd/rsyncd.motd
    log file = /var/log/rsyncd.log
    pid file = /var/run/rsyncd.pid
    lock file = /var/run/rsyncd.lock
    port = 8730

    #Module Options begin here
    [rsyncd_module]
    path = /ftp/pub/rsyncd
    comment = My Very Own Rsync Server. This area is ReadOnly
    max connections = 3
    timeout = 300
    uid = myuserid
    gid = vuser
    read only = yes
    list = yes
    auth users = rsync_user
    secrets file = /etc/rsyncd/secrets
    hosts allow = xxx.xxx.xxx.xxx/xx
    hosts deny = *

    Replace the module name, myuserid, vuser and rsync_user as necessary for your system.
    If you want to limit those who have access to your rsync server, then specify the “auth users” and “secrets file”. If you want to restrict where they can access the rsync server from, then you will also need the “hosts allow” and “hosts deny” variables. The value for “hosts allow” should be set to your IP address if you use a static IP (example 10.0.0.1/32) or the range if you use a dynamic IP (example 10.0.0.1/16). Multiple possibilities can be separated by a space. If you don’t understand this bit, then leave “hosts allow” and “hosts deny” out of your configuration for now.

  • Create the secrets file pico /etc/rsyncd/secrets. Format is username:password in plain text, one user per line. If you want to communicate over SSH, then ensure that one of the users is your account’s user id; it need not have the same password here as for logging in.
  • The secrets file must not be readable by other users, so change the access rights by using the command chmod 600 /etc/rsyncd/secrets
  • Create your Message Of the Day file pico /etc/rsyncd/rsyncd.motd. This text will be displayed when a connection is made to your server.