sadeghpro :
I use nginx reverse proxy to connect tomcat and nginx config is:
server {
listen 80;
listen [::]:80;
server_name magnet.s-m.local;
location / {
proxy_pass http://tomcat:8080/magnet/;
proxy_cookie_path /magnet /;
proxy_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;
proxy_set_header X-Forwarded-Host $server_name;
}
}
every this is ok but when I want to redirect user spring add project name to redirect path.
@RequestMapping(value = "/login",method = RequestMethod.POST)
public String loginCheck(HttpSession session, @RequestParam("username") String user, @RequestParam("password") String password){
session.setAttribute("username",user);
return "redirect:/home";
}
this code redirect to http://magnet.s-m.local/magnet/home
but I want to redirect http://magnet.s-m.local/home
if I use RedirectView
it's work nice but using redirect:/home
is better because I can decide to redirect or load jsp file if login failed.
Samuel Philipp :
Try removing proxy_redirect
and proxy_set_header Host
parameters from your nginx configuration:
location / {
proxy_pass http://tomcat:8080/magnet/;
proxy_cookie_path /magnet /;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
}
You also can specify the proxy_redirect
more in detail, but it should be activated.