Setting up Tomcat in nginx proxy

南楼画角 提交于 2020-07-10 07:21:10

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!