Passing data to CGI scripts via PATH_INFO

Hi

We are having an issue passing data to CGI scripts via PATH_INFO
environment variable.

for example:-

http://domain.com/cgi-bin/script.cgi/=

On various apache servers this works fine and the PATH_INFO variable
will contain “/=”, on our nginx server we are getting a 403 forbidden
error. We are using fcgiwrap [1] for running CGI and .cgi scripts are
executing.

Could this be an issue with nginx configuration?

Thanks for your time.
Regards

Phil

[1] https://nginx.localdomain.pl/wiki/FcgiWrap

On Thursday 22 May 2014 16:26:54 Phil Knight wrote:

will contain “/=”, on our nginx server we are getting a 403 forbidden
error. We are using fcgiwrap [1] for running CGI and .cgi scripts are
executing.

Could this be an issue with nginx configuration?
[…]

Most likely this is an issue with the configuration.

Actually nginx knows nothing about CGI and it’s environment variables
(including PATH_INFO), so you are free to set it any value you think
reasonable.

wbr, Valentin V. Bartenev

On 22/05/2014 19:32, Valentin V. Bartenev wrote:

On various apache servers this works fine and the PATH_INFO variable
will contain “/=”, on our nginx server we are getting a 403 forbidden
error. We are using fcgiwrap [1] for running CGI and .cgi scripts are
executing.

Could this be an issue with nginx configuration?
[…]

Most likely this is an issue with the configuration.

I think the relevant part is here:

location /cgi-bin/ {
root /users/folder;
gzip off;
fastcgi_pass unix:/var/run/fcgiwrap.socket;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;

         fastcgi_param       DOCUMENT_ROOT /users/folder/cgi-bin/;
         fastcgi_param       SCRIPT_FILENAME

$document_root$fastcgi_script_name;
fastcgi_connect_timeout 120;
fastcgi_send_timeout 120;
fastcgi_read_timeout 120;
}

I could be wrong. Any pointers would be very much appreciated.

I’ve noticed that:

http://domain.com/cgi-bin/no_existent_script.cgi

Also gives a 403. So I suspect that nginx is looking for a file called =
in a folder named api.cgi/
I’m not sure what configuration we need to do to fix this.

Lyle

On 22/05/2014 22:52, Valentin V. Bartenev wrote:

have set.
Module ngx_http_fastcgi_module
Ah, I see. It’s the FastCGI module that’s reading the wrong filename.

I think I understand the process now. Nginx is passing variables to the
fastcgi module, as defined in the config. One of these being:
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
$fastcgi_script_name being everything after http://…/ by default. So
FastCGI was trying to open a file that didn’t exist. The
fastcgi_split_path_info variable addresses this issue, by overloading
$fastcgi_script_name and $fastcgi_path_info with the split from the
regexp. So adding the following:

fastcgi_split_path_info ^(.+.(?:cgi|pl))(.*)$;

Before the fastcgi_param instructions has fixed the issue. Hooray!

Thanks for your help.

Lyle

On Thursday 22 May 2014 22:14:23 Lyle wrote:

I think the relevant part is here:
fastcgi_param PATH_INFO $fastcgi_path_info;

I’ve noticed that:

http://domain.com/cgi-bin/no_existent_script.cgi

Also gives a 403. So I suspect that nginx is looking for a file called =
in a folder named api.cgi/
I’m not sure what configuration we need to do to fix this.
[…]

As I already said, nginx knows nothing about CGI. It doesn’t look for
any
files in your location with “fastcgi_pass”. It just passes request and
all the FastCGI params that you have configured with the values that you
have set.

For example, since you have:

fastcgi_param PATH_INFO $fastcgi_path_info;

and missing the fastcgi_split_path_info directive, then probably nginx
pases
empty string in PATH_INFO.

Please, check the docs to figure out how exactly the $fastcgi_path_info
variable works and what values it takes:
http://nginx.org/en/docs/http/ngx_http_fastcgi_module.html#var_fastcgi_path_info

The whole list of variables with links to descriptions can be found
here:
http://nginx.org/en/docs/varindex.html

Then, probably, you need to check fcgiwrap documentation to figure out
what
variables it expects and how they are processed.

wbr, Valentin V. Bartenev