Running CGI scripts on NGINX
<p>I know this question has already been asked, but there were no clear answers on that question (<a href="https://stackoverflow.com/questions/11667489/how-to-run-cgi-scripts-on-nginx">How to run CGI scripts on Nginx</a>) that would help me. In my case, I have installed NGINX by using source code, and have fixed my .config file so that I can read .php files using FASTCGI successfully. However, I am having quite some issues when it comes to running CGI scripts. I know I have FAST CGI installed and set up, so am I supposed to be naming these .cgi files .fcgi instead? Or am I supposed to include someway for the .cgi file to know that it is working with FAST CGI?? I tried toying around with the nginf.conf file to include .fcgi, and it looks something like this right now:</p>

<pre><code>worker_processes  2;

pid        logs/nginx.pid;
error_log syslog:server=unix:/dev/log,facility=local7,tag=nginx,severity=error;

events {
worker_connections  1024;
}


http {
include       mime.types;
default_type  application/octet-stream;

access_log syslog:server=unix:/dev/log,facility=local7,tag=nginx,severity=info combined;

sendfile        on;
keepalive_timeout  65;


server {
    listen       80;
    server_name  localhost;
        root   /home/parallels/Downloads/user_name/nginx/html;
    location / {

 index index.html index.htm new.html;
        autoindex on;
    }

location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass 127.0.0.1:9000;
 #fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
fastcgi_param  HTTPS              off;
include fastcgi_params;
fastcgi_buffer_size 16k;
fastcgi_buffers 4 16k;
}
location ~ \.pl|fcgi$ {
  try_files $uri =404;
  gzip off;
  fastcgi_pass  127.0.0.1:9000;
  fastcgi_index index.pl;
  #fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
  include fastcgi_params;
  } 

    #error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   html;
    }
}
}
</code></pre>

<p>However, whenever I run a .fcgi script such as </p>

<pre><code>#!/usr/bin/perl

print "Content-type: text/html\n\n";
print "&lt;html&gt;&lt;body&gt;Hello, world.&lt;/body&gt;&lt;/html&gt;";
</code></pre>

<p>I am greeted with a screen that looks like this:</p>

<p><a href="https://i.stack.imgur.com/2kA6W.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/2kA6W.png" alt="enter image description here"></a></p>

<p>I'm pretty sure this is not normal; I should just be seeing <code>Hello, world.</code> on my screen, not all the code as well. Please let me know if my thinking that is actually wrong and this is supposed to be the correct output.</p>

<p>Additionally, on a side note, if I had this as my <code>files.fcgi</code> file:</p>

<pre><code>#!/usr/bin/perl
my $output = `ls`;
print $output
</code></pre>

<p>Running something like this returns a list of all files in the directory that the .fcgi file is located in. Is there anyway I could display this on the web browser? Looking at examples online, it seems like people have been able to just run <code>file.fcgi</code> on their browser and see the output of the shell command (which led me to believe I'm doing something wrong, because when I run it on the command line it lists all the files but on the browser, it just prints out my code). Does anyone know what I could possibly doing wrong, assuming I am doing something wrong. If you need any more information, please let me know! </p>

<p>Thank you, and have a good day!</p>