Table of Contents

Nginx Configuration Examples

How to use CGI in NGINX



Ubuntu

Install

# apt  install fcgiwrap

Configuration

/etc/nginx/sites-available/default

...

    #CGI
    location ~ \.cgi$ {
        root /var/www/html/;
        fastcgi_pass  unix:/var/run/fcgiwrap.socket;
        fastcgi_index  index.cgi;
        fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }

...


CentOS

Install

# yum install epel-release
# yum install spawn-fcgi fcgi-devel
# yum install fcgiwrap


Configuration of spawn-fcgi

/etc/init.d/fcgiwrap

# which fcgiwrap
/sbin/fcgiwrap

# vi /etc/sysconfig/spawn-fcgi
OPTIONS="-u nginx -g nginx -a 127.0.0.1 -p 9001 -P /var/run/spawn-fcgi.pid -- /sbin/fcgiwrap"

# systemctl status spawn-fcgi
# systemctl start spawn-fcgi
# systemctl status spawn-fcgi

# chkconfig --list
# /sbin/chkconfig spawn-fcgi on
# chkconfig --list


Configuration of Nginx

server {

(abbr)

    location ~ \.cgi$ {
        root /usr/share/nginx/html/;
        fastcgi_pass   127.0.0.1:9001;
        fastcgi_index  index.cgi;
        fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }

(abbr)

}