nginx serving R scripts via CGI/FastRWeb

Francis Daly francis at daoine.org
Wed Feb 20 21:44:05 UTC 2013


On Wed, Feb 20, 2013 at 08:28:27PM +0000, Stefan Parvu wrote:

>         location ~ ^/cgi-bin/R/ {

That will match anything starting with /cgi-bin/R/, which is (most of)
what you want.

These requests will...

>             fastcgi_pass  unix:/opt/sdr/report/ws/fastcgi_temp/nginx-fcgi.sock;

be sent to the fastcgi server.

Now, for all of these requests, you want to tell the fastcgi server to
use the file /opt/sdr/report/docroot/cgi-bin/R. So:

>             fastcgi_index index.cgi;

you don't need that, since it will never apply; and

>             fastcgi_param SCRIPT_FILENAME /opt/sdr/report/docroot/$fastcgi_script_name;

that should be something that expands to
/opt/sdr/report/docroot/cgi-bin/R. Which is probably
$document_root/cgi-bin/R; you can use whatever matches exactly that
filename. $fastcgi_script_name does not have the correct value by default,
in this case.

>             fastcgi_param PATH_INFO $fastcgi_path_info;

If your application uses PATH_INFO, then you'll want to set it something
like that. I don't think that $fastcgi_path_info actually has a value
by default, though.

>             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 REQUEST_URI        $request_uri;
>             fastcgi_param DOCUMENT_URI       $document_uri;
>             fastcgi_param DOCUMENT_ROOT  /opt/sdr/report/docroot;

They are all fairly standard; probably only the first and last matter,
but it depends on your fastcgi server and your application. The last
one would usually be written to use $document_root, but anything that
ends up with the correct value is good.

Note that your fastcgi server, from the logs you provide, either wants
SCRIPT_FILENAME to be correct, or DOCUMENT_ROOT and SCRIPT_NAME to be
correct; and you don't provide a SCRIPT_NAME.

That may not matter when SCRIPT_FILENAME points to the R binary.

> Testing any calls for /cgi-bin/R/foo returns:
> Cannot get script name, are DOCUMENT_ROOT and SCRIPT_NAME (or SCRIPT_FILENAME) set and is the script executable?
> Cannot get script name, are DOCUMENT_ROOT and SCRIPT_NAME (or SCRIPT_FILENAME) set and is the script executable?

>From the above config, SCRIPT_FILENAME was probably
/opt/sdr/report/docroot/cgi-bin/R/foo, which is not an executable file.

> Im trying to see if fastcgi_split_path_info might help anything.

Yes.

http://nginx.org/r/fastcgi_split_path_info

It will change the values of $fastcgi_script_name and $fastcgi_path_info.

	f
-- 
Francis Daly        francis at daoine.org



More information about the nginx mailing list