[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 584
  • Last Modified:

Apache Virtual hosts and CGI

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
fast74
Asked:
fast74
  • 2
  • 2
2 Solutions
 
kenfcampCommented:
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
 
samriCommented:
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
 
fast74Author Commented:
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
 
kenfcampCommented:
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
 
samriCommented:
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

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now