简体   繁体   中英

nginx rewrite url removing subfolder

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

根据您的描述,您只需要将fastcgi指向正确的位置:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM