![Centos 5.5-从多个位置运行 cgi 脚本](https://linux22.com/image/565081/Centos%205.5-%E4%BB%8E%E5%A4%9A%E4%B8%AA%E4%BD%8D%E7%BD%AE%E8%BF%90%E8%A1%8C%20cgi%20%E8%84%9A%E6%9C%AC.png)
我希望能够从 /var/www/cgi-bin 以外的其他位置运行 cgi 脚本,例如:
/var/www/folder1/cgi-bin
/var/www/folder2/cgi-bin
/var/www/folder3/cgi-bin
我该如何配置服务器来执行此操作?
编辑:这是从我个人托管的网络服务器上的网站运行 cgi 脚本。
答案1
ScriptAlias 是你的叔叔。
从:http://httpd.apache.org/docs/2.2/mod/mod_alias.html#scriptalias
Description: Maps a URL to a filesystem location and designates the target as a CGI script
Syntax: ScriptAlias URL-path file-path|directory-path
Context: server config, virtual host
Status: Base
Module: mod_alias
The ScriptAlias directive has the same behavior as the Alias directive, except that in addition it marks the target directory as containing CGI scripts that will be processed by mod_cgi's cgi-script handler. URLs with a case-sensitive (%-decoded) path beginning with URL-path will be mapped to scripts beginning with the second argument, which is a full pathname in the local filesystem.
Example:
ScriptAlias /cgi-bin/ /web/cgi-bin/
A request for http://example.com/cgi-bin/foo would cause the server to run the script /web/cgi-bin/foo. This configuration is essentially equivalent to:
Alias /cgi-bin/ /web/cgi-bin/
<Location /cgi-bin >
SetHandler cgi-script
Options +ExecCGI
</Location>
答案2
有两种方法可以实现这一点:
1)设置虚拟主机,并在每个虚拟主机下指定ScriptAlias /cgi-bin/ "/your/location"
2)在下面创建子文件夹/var/www/cgi-bin
并使用子文件夹链接到它们,但是使用此方法,您无法离开/var/www/cgi-bin
目录树。