There is an application myapp (Spring Boot 1.4.1) and the corresponding myapp.war. War is deployed to Tomcat 8.5.9 and the application becomes available at http://127.0.0.1:8080/myapp/ . I want the application to be available at http://127.0.0.1:8081/ . For this, a config is written to Nginx:

 server { listen 127.0.0.1:8081; location / { proxy_pass http://127.0.0.1:8080/myapp/; } } 

The page becomes available, but redirects in the code:

 ModelAndView response = ... response.setViewName("redirect:/hello/"); 

they still stick myapp , that is, the redirect goes to page 127.0.0.1:8081/myapp/hello/ .

The situation is similar with the template engine Thymeleaf. Links like @ {/ hello /} are converted to / myapp / hello. With him, the problem can be solved through the crutch @ {~ / hello /}. But the problem is somewhere else.

  • Is this the entire configuration file? - Mikhail Vaysman
  • @MikhailVaysman, no, but this is the main part. The rest is settings of buffers, caches, compression and logs. - Victor Khovanskiy
  • In the shown piece everything is correct - it should work - Mikhail Vaysman
  • one
    The easiest way is to deploy as ROOT.war so that the application responds immediately to http://127.0.0.1:8080/ . Do you have such an opportunity? - Roman
  • one
    You can create several hosts in tomcat (one for each domain, respectively), and in nginx you should remember to transfer the required Host header to tomcat ( proxy_set_header Host $host; for example). - Roman

1 answer 1

The easiest way is not to fight with the rewriting of links, but to deploy the application as ROOT.war (if, of course, there is such an opportunity), so that it immediately responds to http://127.0.0.1:8080/ .

If you need to raise several applications for different domains on one tomcat, then you need to create several hosts in tomcat (one for each domain, respectively), and in nginx you should not forget to send the Host header to tomcat ( proxy_set_header Host $host; for example ).