Translation(s): English -Русский

Install and configure FastCGI for nginx Webservice

FastCGI for nginx

To get FastCGI running for the nginx webservice, you will install the Debian package fcgiwrap. Most of the documentation simply tell only aspects of the configuration. For example the SCRIPT_FILENAME and SCRIPT_NAME parameter in the nginx configuration: Both are needed.

This setup is done on a Debian squeeze system with nginx 0.7.67-3 and fcgiwrap 1.0-1.

# apt-get install fcgiwrap

Configure nginx for FastCGI

Add a location configuration for cgi-bin at the proper place.

    location ~ ^/cgi-bin/.*\.cgi$ {
        gzip           off;
        root           /var/www/nginx-default;
        fastcgi_pass   unix:/var/run/fcgiwrap.socket;
        # include      fastcgi_params;
        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_FILENAME    $document_root$fastcgi_script_name;
        fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
        fastcgi_param  REQUEST_URI        $request_uri;
        fastcgi_param  DOCUMENT_URI       $document_uri;
        fastcgi_param  DOCUMENT_ROOT      $document_root;
        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;

        # According to RFC3875 ( in SERVER_NAME
        # we should put actual hostname user came to. For nginx it is in $host
        # This will allow to run multihost instances
        fastcgi_param  SERVER_NAME        $host;

Most part of the fastcgi_param area are copy and pasted by the web sources. The interesting parts are

The root variable must set to the directory, where the cgi-bin directory lives. If you left the root variable in the location configuration, then nginx uses his default directory /usr/local/nginx/html/cgi-bin/ScriptName.cgi. You cant' use only the full path in the fastcgi_param SCRIPT_FILENAME variable. This won't work!

The fastcgi_param SCRIPT_FILENAME variable set the fullpath of the script. In my example the documentroot and fastcgi_script_name variable are used.

The fastcgi_param SCRIPT_NAME variable set the cgi script filename only.

All three parameters (root, fastcgi_param SCRIPT_FILENAME, fastcgi_param SCRIPT_NAME) are important.

CategorySoftware CategorySystemAdministration