There is a partially related question here but it doesn't help me.
For site.com
I have
location /sub/ {
proxy_set_header Accept-Encoding "";
proxy_pass http://192.168.1.1/ ;
}
The 192.168.1.1 IP has a VM with an Apache server on it.
Now when I go to either site.com/sub
or site.com/sub/
, it works fine as expected.
But when I go to site.com/sub/sub1
, it redirects to 192.168.1.1/sub1/
whereas site.com/sub/sub1/
(with trailing slash) works as expected.
Using a proxy_redirect
doesn't seem to make a difference. I also tried using with a regex but to no avail.
location ~/sub/?(.*)$ {
proxy_set_header Accept-Encoding "";
proxy_pass http://192.168.1.1/$1 ;
}
Setting the header Host
just redirects to site.com/sub1/
.
Nginx logs show a 301 redirect.
I can easily solve the problem by simply creating a new location block for /sub/sub1/ but I would really like to be able to handle it in the same block.
As site.com/sub/sub1/
with the trailing slash already works fine, how can I get site.com/sub/sub1
to work correctly instead of redirecting to 192.168.1.1/sub1
? What am I missing here?
I believe I may have solved the problem by using a
proxy_redirect
. What I had tried first (when posting the question) was a proxy redirect forWhat worked was
I got to the answer by carefully examining the nginx logs and the curl -I output