I'm trying to deploy an web application on tomcat server fronted with Nginx. The problem I encounter is tag in my jsp pages is printing out "incorrect" (it is correct from tomcat point of view) context path.
My Web app on tomcat is deployed on context path: /webApp1 with tomcat running on port 8080. So the web application is accessible via http://localhost:8080/webApp1
My nginx is configured to proxy_pass as follows:
location / {
http://localhost:8080/webApp1;
}
With this configuration, the web app is supposed to work with url http://localhost
This only works for the home page text. The home page loaded successfully but all the links on home page have /webApp1 prefixed as tomcat think that it is running by itself hence the output the contextpath as prefix for all links.
Has anyone fixed this before.
All answers are much appreciated.
z.
I managed to fix this problem after spending lots of time.
There's a 3rd party module for nginx HttpSubsModule, which allows you to replace strings in the response body (eg. html).
So the problem can be fixed by:
location / {
http://localhost:8080/webApp1;
subs_filter_types text/html;
subs_filter '/webApp1' '';
}
It'll remove all the context '/webApp1' from the html responses.
Hope this helps others who encountered this problem too.
z.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With