FastCGI tricks,,, keeping seperate log files for virtual hosts

yalcin Bozcaada (
Mon, 14 Jul 1997 14:09:11 -0400

Message-Id: <>
From: yalcin Bozcaada <>
To: ""
Subject: FastCGI tricks,,, keeping seperate log files for virtual hosts
Date: Mon, 14 Jul 1997 14:09:11 -0400


Just a little suggestion for people who do virtual hosting and wanted to automate
their logging into seperate files for each host.

I did my work and tests using Open Market's SecureWebServer 2.0.x and 
fastcgi kit 1.5.1.

First, you don't want to duplicate the logging, so you can turn off logging in your
httpd.config file.

The trick is using an authorizer program and authorizing the region /* and letting
everything go. But, before you let the client request, go grab the virtual host name
or port and log it the way you want into another file.

Here is a main structure of the program:

char *VirtHost;
FILE *logfile;
FILE *A, *B;
/** your seperate log files for different hosts **/
A = fopen("","a+");
B = fopen("","a+");

while( FCGI_Accept() )
     VirtHost = getenv("SERVER_ADDR");
      if( strcmp(VirtHost,"") == 0 ) logfile = A;
      if( strcmp(VirtHost,"") == 0 ) logfile = B;
         after determining which file to write to, fill into your own
         customized log file
      fprintf(logfile,"\r\nAccess by %s / URL = %s ",rmhost, urlpath );
      /** now let the server continue with the URL **/
      printf("Status: 200 OK\r\n" ...


Now, this program should run really fast. At least faster than the URLs that
go to the server most of the time. But, in case a broken pipe problem, the number
of FastCGI processes could be increased along with listener-queue-depth.

There is an annoying issue I came accross so far.  If a URL has been authorized
by another FastCGI authorizer and there is a redirect on success, that would be 
missed. I am trying to find a workaround for that too.