问题
I'm setting up my web server and I need to run tomcat on http://ip/tomcat/
instead of http://ip:8080/
. How I can do this on nginx?
I've tried to find an answer in the internet, but all of them is useless for me.
My nginx configuration:
upstream tomcat {
server ip:8080;
}
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
location /tomcat/ {
proxy_pass http://tomcat;
}
}
Server answer: server answer image
回答1:
You can use /tomcat/ location with using below tag.
location /tomcat/ {
proxy_pass http://tomcat/;
}
When you are going to access manager page it opens http://IP/manager instead of http://IP/tomcat/manager cause /manager/html is harded in tomcat webapps/ROOT/index.jsp
<div class="button">
<a class="container shadow" href="/manager/html"><span>Manager App</span></a>
</div>
If you want to access manager through tomcat location then change below code in tomcat ROOT/index.jsp
<div class="button">
<a class="container shadow" href="/tomcat/manager/html"><span>Manager App</span></a>
</div>
Restart tomcat and test.
回答2:
Use below reverse proxy and test.
location /tomcat/ {
proxy_pass http://tomcat/;
}
Note: In IP address you need to use tomcat IP.
来源:https://stackoverflow.com/questions/61842537/setting-up-tomcat-in-nginx-proxy