install and run the FastCGI helper
apt -y install fcgiwrap systemctl list-unit-files | grep fcgi systemctl status fcgiwrap.socket ls -lhF /var/run/fcgiwrap.socket systemctl status fcgiwrap.service
make sure NGINX is ready for that
ls -lhF /etc/nginx/fastcgi_params #ls -lhF /etc/nginx/fastcgi.conf
make sure your script is executable and test it
vhost=host.example.com
mkdir -p /data/www/$vhost/
cat > /data/www/$vhost/index.cgi <<-EOF9
#!/bin/ksh
cat <<EOF
Content-type: text/html
<p>hello \`host \$REMOTE_ADDR | awk '{print \$NF}'\` (\$REMOTE_ADDR)
EOF
EOF9
chmod +x /data/www/$vhost/index.cgi
ls -lhF /bin/ksh
export REMOTE_ADDR=::1
/data/www/$vhost/index.cgi
unset REMOTE_ADDR
and setup those parms into the vhost server stanza e.g.
vi /etc/nginx/conf.d/$vhost.conf
root /data/www/$server_name;
index index.cgi maintenance.html;
location ~ (\.cgi|\.py|\.sh|\.pl|\.lua)$ {
gzip off;
fastcgi_pass unix:/var/run/fcgiwrap.socket;
include fastcgi_params;
fastcgi_param DOCUMENT_ROOT /data/www/$server_name;
fastcgi_param SCRIPT_FILENAME /data/www/$server_name$fastcgi_script_name;
}
note. be careful with $server_name in the fastcgi parameters: if you do not use a vhost the server name becomes _
note. include fastcgi_params points to conf/fastcgi_params already
which nginx nginx -t nginx -s reload #nginx -s reopen #systemctl restart nginx
check what user’s nginx running as
ps auxfw | grep nginx
eventually fix the underlying cgi daemon for that purpose
vi /usr/lib/systemd/system/fcgiwrap.service User=nginx Group=nginx vi /usr/lib/systemd/system/fcgiwrap.socket SocketUser=nginx SocketGroup=nginx systemctl daemon-reload systemctl restart fcgiwrap.socket systemctl restart fcgiwrap.service ls -lF /var/run/fcgiwrap.socket