nginx rewrite url removing subfolder

偶尔善良 提交于 2020-01-07 02:48:06

问题


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;


来源:https://stackoverflow.com/questions/20453205/nginx-rewrite-url-removing-subfolder

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!