Solved

Apache Virtual hosts and CGI

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

By default, Carbonite Server Backup manages your encryption key for you using Advanced Encryption Standard (AES) 128-bit encryption. If you choose to manage your private encryption key, your backups will be encrypted using AES 256-bit encryption.
How to update Firmware and Bios in Dell Equalogic PS6000 Arrays and Hard Disks firmware update.
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 …
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

738 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