[UE] Running cgi script for prefix
Added by matwey about 6 years ago
Hello,
I am running lighttpd 1.4.45 on Linux system.
I need to migrate very legacy configuration from Apache web server:
<Directory "/path"> Script PUT /cgi-bin/script.cgi </Directory>
This runs cgi script script.cgi for PUT requests on URLs prefixed with /path. I.e. every PUT request to http://example.com/path/foo/bar ends with running the cgi script.
Currently, I managed to have the following lighttpd configuration:
$HTTP["url"] =~ "^/cgi-bin" { cgi.assign = ( "" => "" ) } $HTTP["url"] =~ "^/path" { $HTTP["request-method"] =~ "^PUT$" { url.rewrite-once += ( "^/path(.*)" => "/cgi-bin/script.cgi" ) } }
My issue is the following: PATH_TRANSLATED environment variable is empty in the cgi script which is relied upon it existence. I suppose that my mod_rewrite approach is the wrong way to achieve the goal. Could you please advice me what I am doing wrong?
Replies (5)
RE: Running cgi script for prefix - Added by gstrauss about 6 years ago
lighttpd $HTTP["url"] =~ "..."
is similar to Apache <Location ~ ...>
, not <Directory ...>
so please check that.
PATH_TRANSLATED is set for CGI scripts only in the presence of PATH_INFO. If you're not seeing PATH_TRANSLATED, then there was no PATH_INFO.
https://www.w3.org/CGI/
https://tools.ietf.org/html/draft-robinson-www-interface-00
You should probably fix your script to work with the CGI variables available for the request you are making.
RE: Running cgi script for prefix - Added by matwey about 6 years ago
Will rewrite-once set correct PATH_INFO for me?
RE: Running cgi script for prefix - Added by gstrauss about 6 years ago
Methinks you need to spend some time on some internet search engines to
a) understand what PATH_INFO is and when it is present (and when it is not present)
b) modify your test URL to include a path that will turn into PATH_INFO (and also PATH_TRANSLATED)
c) test
(Hint: this isn't the forum to teach you the basics of CGI. You're going to be very disappointed if you haven't figured that out yet.)
I suggest you start with a basic "Hello World!" CGI script which prints the environment, and access it through lighttpd. Make small changes and test after each small change.
#!/bin/sh echo "Status: 200" echo "Content-Type: text/plain echo echo "Hello World!" echo env | sort