nginx rewrite url removing subfolder

2019-09-02 03:30发布

问题:

I am struggling a bit with rewriting some urls in nginx

I have a site: foo.com/

foo.com/index.html has a link to foo.com/bar.cgi (maybe with with GET arguements)

my cgi resides in /var/www/site/cgi-bin/ and thus it is accesible via foo.com/cgi-bin/bar.cgi

I was hoping the rewrite would remove the cgi-bin part

    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;
        }

回答1:

From what you describe you only have to point fastcgi to the right place:

fastcgi_param SCRIPT_FILENAME var/www/site/cgi-bin$fastcgi_script_name;