Context path for tomcat web application using Nginx as a reverse proxy

I am trying to deploy a web application on a tomcat server using Nginx. The problem I am facing is a tag on my jsp pages that displays the “wrong” (this is true from the point of view of tomcat) context path.

My tomcat web application is deployed in the context path: / webApp1 with tomcat running on port 8080. Thus, the web application is accessible via http: // localhost: 8080 / webApp1

My nginx is configured on proxy_pass as follows:

location / {
    http://localhost:8080/webApp1;
}

In this configuration, the web application should work with the url http: // localhost

This only works for homepage text. The homepage loaded successfully, but all the links on the main page have / webApp 1, the prefix is ​​like tomcat, they think that it works by itself, therefore it displays the context line as a prefix for all links.

Has anyone fixed this before.

All answers are greatly appreciated.

g.

+3
source share
1 answer

I managed to solve this problem after spending a lot of time.

There is a third-party module for nginx HttpSubsModule , which allows you to replace the lines in the body of the response (for example, html).

Thus, the problem can be fixed:

location / {
    http://localhost:8080/webApp1;
    subs_filter_types text/html;
    subs_filter '/webApp1' '';
}

It will remove the entire '/ webApp1' context from the html responses.

Hope this helps others who run into this issue.

g.

+3
source

All Articles