Regardless of what I do, Nginx keeps breaking my url's. I believe this only occurs when the response contains a redirect. I believe I have tried every combination of suggestions from the wiki and the first 20 or so pages on google by now to no avail.
My configuration looks something like this:
upstream tomcat {
server 10.0.0.1:8080;
}
upstream opsview {
server 127.0.0.1:3000;
}
server {
listen 80;
server_name example.com;
location / {
proxy_pass http://tomcat/;
proxy_redirect http://tomcat/ /;
server_name_in_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
I have tried:
- both upstreams (and they behave differently)
- passing and redirecting directly to the ip:port instead of to an upstream
- with and without trailing slashes
- proxy_redirect off
- with and without the server_name_in_redirect off
- with and without the header directives
The error cases that keep coming back:
- If proxying to an external host, I am liable to find my browser literally redirected to http://tomcat/.
- If proxying to another service on the same host, I am liable to find my browser redirected to the other port: http://example.com:3000/.
What on earth am I doing wrong?
You should check what really upstream returns in
Location:
HTTP header when it does redirect. It is possible thatLocation:
has URL like http://tomacat.fully.qualifyed.name/somepath/ and this wont matchproxy_redirect http://tomcat/ /
.