Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Apache Virtual hosts and CGI

Posted on 2004-08-30
8
Medium Priority
?
580 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 252 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 248 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

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

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

Your data is at risk. Probably more today that at any other time in history. There are simply more people with more access to the Web with bad intentions.
This article shows how to use a free utility called 'Parkdale' to easily test the performance and benchmark any Hard Drive(s) installed in your computer. We also look at RAM Disks and their speed comparisons.
This tutorial will walk an individual through the process of installing the necessary services and then configuring a Windows Server 2012 system as an iSCSI target. To install the necessary roles, go to Server Manager, and select Add Roles and Featu…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

618 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