Solved

Apache Virtual hosts and CGI

Posted on 2004-08-30
8
570 Views
Last Modified: 2013-11-18
Hi all,
I have apache 2.0 set up with virtual hosts on my RH8 Server. I am having a few problems with getting CGI to work.
Here is a typical Virtual Hosts file:
<VirtualHost *:80>
ServerName mysite.com
ServerAlias www.mysite.com mysite
ServerAdmin hosting@mysite.ie
DocumentRoot "/www/sites/mysite/public_html"
ScriptAlias /cgi-bin/ /www/sites/mysite/public_html/cgi-bin/
CustomLog "/www/sites/mysite/logs/access.log" combined
ErrorLog "/www/sites/mysite/logs/error.log"
CheckSpelling On

<Directory /www/sites/mysite/public_html>
AllowOverride All
Options +Indexes
    Order allow,deny
    Allow from all
</Directory>

</VirtualHost>

The main httpd.conf has its own ScriptAlias but it is commented out.

The error.log file contains the line:
File does not exist: /www/sites/cgi-bin, referer: http://212.147.142.245/~mysite/
It should be looking in /www/sites/mysite/public_html/cgi-bin/ instead of /www/sites/cgi-bin???

I am accessing the site by it's IP address for the time being until I can get the domain sorted out:
xxx.xxx.xxx.xxx/~mysite

Finally the form action in the htm file is
<form method="post" action="/cgi-bin/maillist.cgi" name="" target=blank>

When I try to use the form on the site I get:
The requested URL /cgi-bin/maillist.cgi was not found on this server.

any ideas?

Thanks
0
Comment
Question by:fast74
  • 2
  • 2
8 Comments
 
LVL 14

Expert Comment

by:kenfcamp
ID: 11930714
It looks like you may have forgotten to your directory statements for your custom cgi-bin

<Directory /www/sites/mysite/public_html/cgi-bin>
Options +ExecCGI
</Directory>

Alternatly you can use the default cgi-bin (your app will need to place there),
 which will give access to the script(s) for all domains w/o a custom cgi directory

it should be in (/var/lib/apache/ -- or /var/www/) . If not check your httpd.conf
0
 
LVL 15

Expert Comment

by:samri
ID: 11930778
hi Fast74,

You may jump to Apache docs on CGI at http://httpd.apache.org/docs-2.0/howto/cgi.html

Specifically, you could take a look at the examples
http://httpd.apache.org/docs-2.0/howto/cgi.html#configuring

Another thing to look at would be on the Vhost configuration itself (http://httpd.apache.org/docs-2.0/vhosts/) remember that apache will treat the first defined vhost as the default vhost not matching any other vhost configuration.  What happened here is that, when you typed http://1.2.3.4/ where 1.2.3.4 is the IP address of your server -- 1.2.3.4 will be the content of "Host:" header in the request.  Apache would attempt to match this to the respective vhost container, specifically the ServerName and ServerAlias directive in the Vhost container.  That is why the request failed since, the request would fall into the "default" vhost, and chances is, the directory  /www/sites/mysite/public_html/cgi-bin/ is not defined in the default vhost.

The error:
>>  The requested URL /cgi-bin/maillist.cgi was not found on this server.
makes sense (I think) since it tries to refer to the default vhost /cgi-bin/

You could try this approach as recommended by Apache website:
--
If you wish designate a cgi-bin subdirectory of a user's directory where everything will be treated as a CGI program, you can use the following.

* modified to suit your env.

<Directory /www/sites/*/cgi-bin>

Options ExecCGI
SetHandler cgi-script

</Directory>
0
 

Author Comment

by:fast74
ID: 11950830
Hi,
Still doesn't work!
The apache docs was actually the first place I started.
My Virtual hosts file now looks like this:
<VirtualHost *:80>
ServerName mysite.com
ServerAlias www.mysite.com mysite
ServerAdmin hosting@mysite.ie
DocumentRoot "/www/sites/mysite/public_html"
ScriptAlias /cgi-bin/ /www/sites/mysite/cgi-bin/
CustomLog "/www/sites/mysite/logs/access.log" combined
ErrorLog "/www/sites/mysite/logs/error.log"
CheckSpelling On

<Directory /www/sites/mysite/public_html>
AllowOverride All
Options +Indexes
    Order allow,deny
    Allow from all
</Directory>

<Directory /www/sites/mysite/cgi-bin>
Options +ExecCGI
</Directory>
</VirtualHost>

Is there a checklist of things I can go through?

The changes are that now the cgi-bin directory and the public_html directory are in the same folder.
These lines are all commented out of httpd.conf:
# ScriptAlias /cgi-bin/ "/usr/local/apache/cgi-bin/"
#<Directory "/usr/local/apache/cgi-bin">
#    AllowOverride None
#    Options None
#    Order allow,deny
#    Allow from all
#</Directory>

Should they be commented ?
Does anyone know of any good sites that cover this in detail for apache2?

thanks
0
 
LVL 14

Accepted Solution

by:
kenfcamp earned 63 total points
ID: 11953233
Try changing

<Directory /www/sites/mysite/public_html>
AllowOverride All
Options +Indexes
    Order allow,deny
    Allow from all
</Directory>

TO

<Directory /www/sites/mysite>
AllowOverride All
Options +Indexes
    Order allow,deny
    Allow from all
</Directory>
0
 
LVL 15

Assisted Solution

by:samri
samri earned 62 total points
ID: 12008000
hi fast74,

I hope you still need assistance here.

Looking at your latest config.  try to modify your ScriptAlias to look as follows.  And for /www/site/mysite/cgi-bin/ modify thestuff, to look similar to the original cgi-bin dir properties.

ScriptAlias /cgi-bin/ /www/sites/mysite/cgi-bin/
<Directory /www/sites/mysite/cgi-bin>
    AllowOverride None
    Options None
    Order allow,deny
    Allow from all
</Directory>

It doesn;t make sense to add +ExecCGI to those directory already defined as ScriptAlias.  I think it would cause your CGI to crash with error 500.

HTH.
0

Featured Post

Connect further...control easier

With the ATEN CE624, you can now enjoy a high-quality visual experience powered by HDBaseT technology and the convenience of a single Cat6 cable to transmit uncompressed video with zero latency and multi-streaming for dual-view applications where remote access is required.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

VM backups can be lost due to a number of reasons: accidental backup deletion, backup file corruption, disk failure, lost or stolen hardware, malicious attack, or due to some other undesired and unpredicted event. Thus, having more than one copy of …
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
This tutorial will walk an individual through setting the global and backup job media overwrite and protection periods in Backup Exec 2012. Log onto the Backup Exec Central Administration Server. Examine the services. If all or most of them are stop…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question