When I try to request a cgi script from an inets httpd server, I get this error:
sh: /Users/7stud/erlang_programs/inets_proj/cgi-bin/cgi-bin/1.pl:
No such file or directory
I notice that the cgi-bin component of the path is doubled. My cgi script is actually located at:
/Users/7stud/erlang_programs/inets_proj/cgi-bin/1.pl
Here is my httpd server proplist_file:
[
{modules, [
mod_alias,
mod_cgi
]},
{ bind_address, "localhost"},
{port,0},
{server_name,"httpd_test"},
{server_root,"."},
{document_root,"./htdocs"},
{script_alias, {"/cgi-bin/", "./cgi-bin/"} }
].
According to the httpd docs:
CGI Properties - Requires mod_cgi
{script_alias, {Alias, RealName}}
Alias = string() and RealName = string(). Have the same behavior as property alias, except that they also mark the target directory as containing CGI scripts. URLs with a path beginning with Alias are mapped to scripts beginning with RealName, for example:{script_alias, {"/cgi-bin/", "/web/cgi-bin/"}}Access to
http://your.server.org/cgi-bin/foowould cause the server to run the script/web/cgi-bin/foo.
And:
{server_root, path()}
Defines the home directory of the server, where log files, and so on, can be stored. Relative paths specified in other properties refer to this directory.
More info:
5> httpd:info(S).
[{mime_types,[{"htm","text/html"},{"html","text/html"}]},
{server_name,"httpd_test"},
{script_alias,{"/cgi-bin/","./cgi-bin/"}},
{bind_address,{127,0,0,1}},
{modules,[mod_actions,mod_alias,mod_cgi,mod_get,mod_head,
mod_log]},
{server_root,"."},
{port,59641},
{document_root,"./htdocs"}]
6> pwd().
/Users/7stud/erlang_programs/inets_proj
ok
7> ls().
cgi-bin cl.beam cl.erl htdocs
s.beam s.erl server.conf
ok
Why am I getting a doubled cgi-bin component in my request url?
If I use a full path to the server's cgi-bin directory in the
script_aliasoption, then I can successfully request a cgi script. I can't get a relative path to work. This is the httpd server configuration that worked for me:server.conf:
Directory structure:
s.erl:
cgi script 1.pl (make sure the file has executable permissions!):
file1.txt:
In the shell:
In a terminal window:
Despite what the docs say about having to use the host syntax as output by
httpd:info()--rather than what you specify for{bind_address, "localhost"}--I can uselocalhostin the request.Here's an example using
httpcto make a cgi post request to an httpd server:There seems to be something wrong with httpd's implementation of cgi as I am unable to make a cgi post request containing json data. A cgi script has to read the body of the request to get the raw string, and I've tried doing that with both a perl cgi script,
$str = $q->param('POSTDATA');and a python cgi script,my_dict = json.load(sys.stdin)and I can't get the body of the request from the httpd server.