Solved

Apache Virtual hosts and CGI

Posted on 2004-08-30
8
563 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 13

Expert Comment

by:kenfcamp
Comment Utility
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
Comment Utility
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
Comment Utility
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 13

Accepted Solution

by:
kenfcamp earned 63 total points
Comment Utility
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
Comment Utility
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Storage devices are generally used to save the data or sometime transfer the data from one computer system to another system. However, sometimes user accidentally erased their important data from the Storage devices. Users have to know how data reco…
VM backup deduplication is a method of reducing the amount of storage space needed to save VM backups. In most organizations, VMs contain many duplicate copies of data, such as VMs deployed from the same template, VMs with the same OS, or VMs that h…
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…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

728 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now