title: nginx rewrite url removing subfolder
body: <p>I am struggling a bit with rewriting some urls in nginx</p>
  
  <p>I have a site: foo.com/</p>
  
  <p>foo.com/index.html  has a link to foo.com/bar.cgi (maybe with with GET arguements)</p>
  
  <p>my cgi resides in /var/www/site/cgi-bin/ and thus it is accesible via foo.com/cgi-bin/bar.cgi</p>
  
  <p>I was hoping the rewrite would remove the cgi-bin part</p>
  
  <pre><code>    location ~ \.cgi$ {
          root /var/www/localhost;
          #rewrite ^/cgi-bin/(.*)$ $1 permanent;
  
          fastcgi_param SCRIPT_FILENAME/ /var/www/localhost$fastcgi_script_name;
          include /etc/nginx/fastcgi.conf;
          fastcgi_pass unix:/var/run/fcgi.sock-1;
          }
  </code></pre>