I use nginx as front-end server and tomcat as back-end. The clients access my site via https scheme. For example:
https://example.com/app/test
Nginx receive this and pass the request to tomcat via this local address:
http://localhost:8080/app/test
My nginx config:
location / {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forward-For $remote_addr;
proxy_set_header X-Forward-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forward-Proto $scheme;
proxy_pass http://localhost:8080;
}
This works fine. However, when I try to use redirect (http 302), it always turn https to http. This is my redirect code:
response.sendRedirect("/app/redirect-test");
What I expecting is to redirect the browser to:
https://example.com/app/redirect-test
but it always redirects the browser to:
http://example.com/app/redirect-test.
I also log the headers to track this issue:
host : example.com
x-real-ip : 180.168.202.246
x-forward-for : 180.168.202.246
x-forward-proto : https
connection : close
......
But I still cannot figure out. And I try to log request.getRequestURL(), then I get this result:
http://example.com/app/test
How can I solve this problem?