Forum: NGINX passing data to CGI scripts via PATH_INFO

327b1e4d91880f0c1a277540101ed0db?d=identicon&s=25 Phil Knight (Guest)
on 2014-05-22 17:27
(Received via mailing list)
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
40b4c848b8fcd63b0cb60b9d170c3a77?d=identicon&s=25 Valentin V. Bartenev (Guest)
on 2014-05-22 20:33
(Received via mailing list)
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
Fd3cf7443ec490fcaab7d899a699dd20?d=identicon&s=25 Lyle (Guest)
on 2014-05-22 23:14
(Received via mailing list)
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
40b4c848b8fcd63b0cb60b9d170c3a77?d=identicon&s=25 Valentin V. Bartenev (Guest)
on 2014-05-22 23:53
(Received via mailing list)
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_mod...

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
Fd3cf7443ec490fcaab7d899a699dd20?d=identicon&s=25 Lyle (Guest)
on 2014-05-23 11:18
(Received via mailing list)
On 22/05/2014 22:52, Valentin V. Bartenev wrote:
> have set.
> http://nginx.org/en/docs/http/ngx_http_fastcgi_mod...
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
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.