title: How to run c++ CGI script on NGINX server
body: <p>I have written below lines in configuration file created in /etc/nginx/conf.d named as "helloworld.local.conf". </p>
  
  <pre><code>server{
       listen 80 default_server;
       server_name hello_world;
       location / {
            root /var/www/helloworld;
            fastcgi_pass 127.0.0.1:9000;
       } 
  }
  </code></pre>
  
  <p>There is an index.html file in /var/www/helloworld which is displaying text "site comming soon".</p>
  
  <p>My c++ code looks like below:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include "fcgio.h"
  
  using namespace std;
  
  int main(void) {
      cout&lt;&lt;"Content-type:text/html\r\n\r\n";
      cout&lt;&lt;"&lt;html&gt;\n";
      cout&lt;&lt;"&lt;head&gt;\n";
      cout&lt;&lt;"&lt;title&gt;Hello World- First CGI Program&lt;/title&gt;\n";
      cout&lt;&lt;"&lt;/head&gt;\n";
      cout&lt;&lt;"&lt;body&gt;\n";
      cout&lt;&lt;"&lt;h2&gt; hello world&lt;/h2&gt;\n";
      cout&lt;&lt;"&lt;/body&gt;\n";
      cout&lt;&lt;"&lt;/html&gt;\n";
      return 0;
  }
  </code></pre>
  
  <p>I have the c++ binary code file is produced using the following command</p>
  
  <pre><code>g++ abc.cpp -lfcgi++ -lfcgi -o hello_world
  </code></pre>
  
  <p>which is needed to be deployed on the NGINX server. I searched and tried different ways to run this script on the stackoverflow but still missing something.</p>
  
  <p>I also ran the below command to connect c++ binary code file to server</p>
  
  <pre><code>cgi-fcgi -start -connect 127.0.0.1:9000 ./hello_world
  </code></pre>
  
  <p>Now when i am visiting the address 127.0.0.1:9000 in the browser, not getting "hello world " text which is in the c++ code.</p>
  
  <p>Output: I am suppose to get response as "hello world" from the the c++ binary code and that to be displayed on the html page.</p>
  
  <p>What am i missing please help.</p>
  
  <p>UPDATE: this is my config file now.</p>
  
  <pre><code>server{
      server_name hello;
      location / {
          fastcgi_index index.cgi;
          root /var/www/helloworld;
          fastcgi_pass 127.0.0.1:9000;
          fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_name;
          include fastcgi_params;
      }
  }
  </code></pre>