Our PHP-based application (custom made, no framework) sometimes needs to use its base full URL (for instance to store URL in files send to clients). Based for instance on this question, our application guess this (this is based on comparing __FILE__
and various variables in $SERVER
like SCRIPT_NAME
and SERVER_NAME
).
Now we need to setup a (nginx) reverse-proxy in front of our application. Suppose that we map https://example.com/some/dir/onproxy/
to http://backend/another/dir/onbackend/
.
Is there a way to guess the public URL (https://example.com/some/dir/onproxy/
) from the code on backend
?
AFAIU (from my readings and experiments), it's not possible (HTTP_HOST
may give example.com
but I have found nothing that indicates some/dir/onproxy
) but maybe I'm missing something (some variables or a nginx configuration option).
Any idea ?
In case it's not possible, the only solution is to store https://example.com/some/dir/onproxy/
in the configuration, right ?
EDIT 1
As suggested by @Progman, I tried solutions on this question. I have tried both the accepted answer and the second most upvoted answer but both return (some variation of) the URL on the backend (http://backend/another/dir/onbackend/
).
EDIT 2
I forgot to mention that I would like to avoid to rely on URL rewriting in the proxy.