Forum

Where should I create cgi-bin

Duke Normandin
26 November 2010, 06:20
I have:
VirtualHost {
Hostname = www.my-domain.com
WebsiteRoot = /var/www/hiawatha/my-domain.com/htdocs
FollowSymlinks = yes
ExecuteCGI = yes
StartFile = index.html
AccessLogfile = /var/www/hiawatha/my-domain.com/log/access.log
ErrorLogfile = /var/www/hiawatha/my-domain.com/log/error.log
TimeForCGI = 5
}

So the directory tree is:

/var/www/hiawatha/my-domain.com/htdocs/ => for html files

/var/www/hiawatha/my-domain.com/cgi-bin/ => for all cgi scripts

or should cgi-bin go under /htdocs/?

anyway, I keep getting a 404. TIA....
Hugo Leisink
26 November 2010, 09:25
CGI scripts can be placed in the same directory as your HTML files.
Duke Normandin
26 November 2010, 15:38
Cool! Just tried _that_ - works great! Thanks.

But what if I want to segregate all CGI scripts into cgi-bin/ - how do I tell Hiawatha to go find them _there_? My guess would be:
Directory { 
Path = whatever/cgi-bin
ExecuteCGI = yes
}

Is that correct?
Søren Enevoldsen
26 November 2010, 21:50
Guess you could use URL rewrite perhaps?
^.*/(s+).cgi/(.*)$ Rewrite /cgi-bin/$1.cgi/$2
I'm don't have much experience with regular expression so the above will probably have to be adjusted
Hugo Leisink
26 November 2010, 21:52
Why do you want to have CGI's in a cgi-bin directory??
Duke Normandin
27 November 2010, 02:52
Just the way I've always done it with Apache. Force of habit. More secure? I don't know! I guess that I could symlink to a cgi-bin/ directory somewhere in $HOME.
Hugo Leisink
27 November 2010, 08:45
If you want to do it properly, then cgi-bin should be an alias to a centralized directory. In the old days, not many people knew how to write a CGI script. So, a system administrator wrote some simple form handling CGI scripts for them and placed those in a centralized directory. In every website configuration. he created an alias called cgi-bin which pointed to that centralized directory.

Creating a cgi-bin directory inside the website directory is just a misunderstanding of what the cgi-bin directory was for and adds nothing to security.
Duke Normandin
28 November 2010, 06:03
Maybe it would save a lot of time if you could give us a detailed example of how to set up the proper directories for the html and script files for:

1. a local Hiawatha server for testing purposes

2. a remote Hiawatha production server

I'm confused because you just said, "If you want to do it properly, then cgi-bin should be an alias to a centralized directory", but a couple of days ago you said, "CGI scripts can be placed in the same directory as your HTML files."

Which is it

Thanks!
Hugo Leisink
28 November 2010, 10:37
In the old days, the cgi-bin directory was a directory in which a system administrator placed scripts that users could use to process webforms. This was done because those users lacked the knowledge to create such scripts themselves. The system administrator placed a symlink in every website to that directory so users could actually use those scripts. That was then.

These days, many users are able to create those scripts themselves via, for example, PHP. So, for those users a cgi-bin directory is no longer necessary. Those users can simply create those scripts and placed them along the HTML files and images in the same directory. Placing the CGI scripts in a cgi-bin directory inside the website directory is weird. It adds nothing to security, usability or anything. Although many people still do it, it's just a misunderstanding of what the cgi-bin directory used to be for.

However, if you still want to use a cgi-bin directory, do it properly and make it a centralized directory to which you create an alias in every website. Only do it for users who don't know how to write a CGI script but want to have a, for example, contact form on their website.

If your webserver is only to be used by you (which I guess is the case), forget this whole cgi-bin directory thing and simply place all website stuff in one directory. You can of course place, for example, images in a subdirectory, but that's another thing.
Duke Normandin
28 November 2010, 16:38
"In the old days"? What the hell is all that about?

Here's what Apache.org has to say, at: http://httpd.apache.org/docs/current/mod/mod_alias.html#scriptalias

It is safer to avoid placing CGI scripts under the DocumentRoot in order to avoid accidentally revealing their source code if the configuration is ever changed. The ScriptAlias makes this easy by mapping a URL and designating CGI scripts at the same time. If you do choose to place your CGI scripts in a directory already accessible from the web, do not use ScriptAlias. Instead, use <Directory>, SetHandler, and Options as in:

<Directory /usr/local/apache2/htdocs/cgi-bin >
SetHandler cgi-script
Options ExecCGI
</Directory>
This is necessary since multiple URL-paths can map to the same filesystem location, potentially bypassing the ScriptAlias and revealing the source code of the CGI scripts if they are not restricted by a Directory section.


How is Hiawatha different that the above Apache quote would not be valid? Or are you saying the same thing?
Hugo Leisink
28 November 2010, 18:14
The source code can only be revealed if the CGI settings in hiawatha.conf are changed. Placing the CGI's in an alias directory doesn't prevent revealing the source code. Not in Hiawatha, not in Apache. What the Apache website is saying doesn't make sense.
Duke Normandin
28 November 2010, 18:38


--
dukeofperl@ml1.net
Hugo Leisink
28 November 2010, 18:49
And that means....?
Duke Normandin
28 November 2010, 20:31
Ever since the "old days", it seems that Apache.org has been the de facto authority concerning web servers and the HTTP protocol. And now to find out that they've been full of shit all these years. WTF...
--
dukeofperl@ml1.net
Hugo Leisink
28 November 2010, 20:38
Apache and being 'de facto'... Read about the HTTP PUT method and then take a look about how Apache has it implemented... not the same. Look at PHP's configfile php.ini and look at the comments for the cgi.rfc2616_headers setting. It says that Apache requires that PHP does not send RFC2615 compliant HTTP headers... nice.
Duke Normandin
28 November 2010, 20:53
I hear you!
The world has to be informed of this Hugo!
All those poor mis-guided souls who persist on using Apache, must be re-educated.
Maybe Geert Wilders can help! =D
This topic has been closed.