I’m trying to have nginx proxy various applications on subpaths of the same domain.
My problem is that the links generated by the application use / as their root instead of their subdir.
My configuration is :
location /wiki/ {
proxy_pass http://localhost:4567/;
proxy_set_header SCRIPT_NAME /wiki;
}
I believe proxy_set_header SCRIPT_NAME /wiki; should set the header SCRIPT_NAME, which is use by the application to generate links, but instead HTTP_SCRIPT_NAME is set, which is ignore by the application.
How can I set SCRIPT_NAME so that my links are generated correctly ?
As per CGI specification, http headers are availabe with the
HTTP_prefix:That is, header
Some-Headerwill be seen asHTTP_SOME_HEADERin your application. That is, everything works is expected – you added http header, and got it available withHTTP_prefix.The
SCRIPT_NAMEvariable is special and isn’t set by any header, but instead it’s constructed from URI by the code which runs your application. To change it, you have to actually change URI seen by your backend, i.e. you needOr just no
/wiki/in proxy_pass, as long as it’s inlocation /wiki/anyway, i.e.The bad thing here is that you probably did URI change from
/wiki/to/for some reason, i.e. your backend application expects/. There are several possible solutions to this problem:/wiki/. Usually this is simple to do.