Table of Contents

Simple CGI support for Nginx (fcgiwrap) en Debian / Ubuntu

URL Fcgiwrap: http://nginx.localdomain.pl/wiki/FcgiWrap

Instalar fcgiwrap en Debian / Ubuntu

aptitude install fcgiwrap  

Configurar Nginx

Editar el fichero /etc/nginx/nginx.conf: Usuario, Grupo, socket (/var/run/fcgiwrap.socket) y parámetros.

user www-data www-data;  
   
 events {  
   
 }  
      
 http {  
   
 include mime.types;  
 default_type application/octet-stream;  
   
   server {  
   listen 80;  
   server_name dominio.com;  
   root /var/www/static;  
   index index.html index.cgi;  
   error_log /var/log/nginx/error.log;  
   access_log /var/log/nginx/access.log ;  
   
   location / {  
   root /var/www/static;  
   index index.html index.htm;  
   }  
   
   location ~ ^/cgi-bin/.*\.cgi$ {  
   
      fastcgi_pass unix:/var/run/fcgiwrap.socket;  
      fastcgi_index index.cgi;  
      fastcgi_param SCRIPT_FILENAME  $document_root$fastcgi_script_name;  
      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 REQUEST_URI    $request_uri;  
      fastcgi_param DOCUMENT_URI    $document_uri;  
      fastcgi_param DOCUMENT_ROOT   $document_root;  
      fastcgi_param SERVER_PROTOCOL  $server_protocol;  
      fastcgi_param HTTPS       $https if_not_empty;  
   
      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;  
   }  
   }  
 }  

Un ejemplo muy simple para probar la activación de FastCGI en Nginx.

index.cgi
#!/bin/bash
 
echo "Content-type: text/html"
echo ""
 
echo '<html>'
echo '<head>'
echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">'
echo '<title>Hola mundo</title>'
echo '</head>'
echo '<body>'
echo 'Hola mundo'
echo '</body>'
echo '</html>'
 
exit 0

Dada esta configuración, los ficheros CGI (Python, Perl, C,…) deben tener extensión .cgi y estar en /var/www/static/cgi-bin. Leer la web oficial para más información.

Ejemplo de URL: http://dominio/cgi-bin/script.cgi